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);