I follow the instruction step by step on Zxing Camera in Portrait mode on Android to display portrait while user's using zxing camera.
But it won't work. The scanner is still appeared in the landscape mode. I think it's because i am using the latest version (v3.2.0) of Zxing and the instruction is deprecated.
How can this be done in v3.2.0 Zxing?
Anyway, Here are the steps I've tried:
- Modify buildLuminanceSource(..) DecodeHandler.java
Code:
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;
width = height;
height = tmp;
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(rotatedData, width, height);
- Modify getFramingRectInPreview() in CameraManager.java
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;
Modify initFromCameraParameters(...) in CameraConfigurationManager.java
In Zxing (v3.2.0), I don't find the following code
Code:
//remove the following
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
}
- Add following line to rotate camera in setDesiredCameraParameters(...) in CameraConfigurationManager.java
Code:
camera.setDisplayOrientation(90);
- In my project, modify AndroidManifest.xml
Code:
android:screenOrientation="portrait"