Change zxing for Android to portrait Mode

Source: Internet
Author: User

Recently, I was developing a QR code scan project. I pulled down a zxing source code and then rewritten it. When I modified the zxing for android portrait mode, I encountered the following problems:

You have modified androidmainfest. android: screenorientation = "portrait" is the property of the activity in XML, and the activity is forced to set to portrait mode. However, when the camera is started, the screen is still in Landscape mode. Therefore, I found the following method on the Internet:

For zxing 1.6:

1. Modify the manifest file and set captureactivity to portrait.

android:screenOrientation="portrait"

2. In the decodehandler. Java file, find the decode (byte [], Int, INT) method, and add the following before buildluminancesource is called:

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 are swapping, that's the difference to #11width = height;height = tmp;data = rotatedData;

3. Find the getframingrectinpreview () method in cameramanager. Java and replace the corresponding code:

rect.left = rect.left * cameraResolution.y / screenResolution.x;rect.right = rect.right * cameraResolution.y / screenResolution.x;rect.top = rect.top * cameraResolution.x / screenResolution.y;rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;

4. Find the setdesiredcameraparameters () method in cameraconfigurationmanager. Java and add the Code: (different SDK versions may call different methods)

camera.setDisplayOrientation(90);

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.