Zxing2.1完美竖屏扫描,取景框不会变形【转】
1.修改manifest文件,将CaptureActivity设为portrait
android:screenOrientation="portrait"
2.在DecodeHandler.java文件中,找到decode(byte[],int,int)方法,在buildLuminanceSource调用前,加上如下:
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; data = rotatedData;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;
camera.setDisplayOrientation(90);
Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); if (width < height) { int temp = width; width = height; height = temp; } screenResolution = new Point(height, width); cameraResolution = findBestPreviewSizeValue(parameters, new Point(width, height));