修竖屏时,zxing版本 3.4.1
1、指定activity为竖屏
android:screenOrientation="portrait"
2、DecodeHandler 中,在decode(byte[] data, int width, int height)方法中,增加以下代码
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 #11 width = height; height = tmp; data = rotatedData;
3、CameraManager 方法 getFramingRectInPreview()
3.1 cameraResolution.y和cameraResolution.x互换,修改如下
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