码迷,mamicode.com
首页 > 其他好文 > 详细

【QrCode】Zxing竖屏,并解决变形问题

时间:2015-07-20 19:43:41      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:qr二维码   zxing   

Step 1: Add following lines to rotate data before buildLuminanceSource(..) in decode(byte[] data, int width, int height)

DecodeHandler.java:

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

Step 2: Modify getFramingRectInPreview().

CameraManager.java

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;

Step 3: Disable the check for Landscape Mode in initFromCameraParameters(…)

CameraConfigurationManager.java

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

Step 4: Add following line to rotate camera insetDesiredCameraParameters(…)

CameraConfigurationManager.java

camera.setDisplayOrientation(90);

Step 5: Do not forget to set orientation of activity to portrait. I.e: manifest

版权声明:本文为博主原创文章,未经博主允许不得转载。

【QrCode】Zxing竖屏,并解决变形问题

标签:qr二维码   zxing   

原文地址:http://blog.csdn.net/cngithub/article/details/46970255

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!