Zxing Vertical Screen Switch Android
Zxingdemo downloaded on google is a horizontal screen state
I simply changed the activity to a vertical screen android:screenorientation= "Portrait" in Androidmanifest.xml.
The screen is positive, but the shooting screen is still sideways.
Checked some online information, combined with their own manual commissioning
Summarize here to share
Steps:
1) Change the screenorientation of <activity/> label captureactivity in Androidmanifest.xml to
android:screenorientation= "Portrait"
2) Replace Getframingrectinpreview () in the Cameramanager.java class with the original left right top bottom
Vertical screen rect.left = Rect.left * cameraresolution.y/screenresolution.x; Rect.right = Rect.right * cameraresolution.y/screenresolution.x; Rect.top = Rect.top * CAMERARESOLUTION.X/SCREENRESOLUTION.Y;
3) void Setdesiredcameraparameters (Camera camera) method in Cameraconfigurationmanager.java
Increase before Setparameters
Camera.setdisplayorientation (90);
4) The decode (byte[] data, int width, int height) method in Decodehandler.java
Planaryuvluminancesource Source = Cameramanager.get (). Buildluminancesource (data, width, height);
Previously added:
byte[] Rotateddata = new Byte[data.length]; for (int y = 0, y < height; y++) {for (int x = 0; x < width; x + +) rotateddata[x * height + height-y-1] = data[x + y * width]; } int tmp = width; Here we is swapping, that's the difference to #11 width = height; height = tmp; data = Rotateddata;
5) Replace the Cameraconfigurationmanager initfromcameraparameters (camera camera) method with the following
This method prevents the screen from stretching after the vertical screen
/** * Reads, one time, values from the camera that is needed by the app. */void initfromcameraparameters (camera camera) { Camera.parameters Parameters = camera.getparameters ();p Reviewformat = Parameters.getpreviewformat (); previewformatstring = Parameters.get ("Preview-format"); LOG.D (TAG, "Default Preview format:" + Previewformat + '/' + previewformatstring); WindowManager manager = (WindowManager) context.getsystemservice (context.window_service);D isplay Display = Manager.getdefaultdisplay (); screenresolution = new Point (Display.getwidth (), Display.getheight ()); LOG.D (TAG, "screen resolution:" + screenresolution); Point Screenresolutionforcamera = new Point (); screenresolutionforcamera.x = screenresolution.x; SCREENRESOLUTIONFORCAMERA.Y = SCREENRESOLUTION.Y; Preview size is all something like 480*320, and other 320*480 if (Screenresolution.x < SCREENRESOLUTION.Y) { screenresolutionforcamera.x = SCREENRESOLUTION.Y; ScreenresolutionforcameRA.Y = screenresolution.x; }cameraresolution = getcameraresolution (parameters, screenresolutionforcamera);//cameraresolution = Getcameraresolution (parameters, screenresolution); LOG.D (TAG, "Camera resolution:" + Screenresolution);}
This zxing horizontal screen to switch to vertical screen
Please leave a message below thank you
Want to be useful to you
Resources
http://download.csdn.net/detail/aaawqqq/7278133