Zxing Vertical Screen Switch Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.