zoukankan      html  css  js  c++  java
  • Zxing2.1扫描取景框变形问题解决

    修改竖屏扫描的贴子,2.0之前的都很适用。可是到了2.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;

    3.在CameraManager.java中找到getFramingRectInPreview()方法, 替换相应代码

              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.在CameraConfigurationManager.java里找到setDesiredCameraParameters()方法,在
      camera.setParameters(parameters)之前加入

              camera.setDisplayOrientation(90);

    5.这一步最关键了,之前有人说是去掉一部分代码,这样会导致扫描的东西变扁。正确的方法应该为:在CameraConfigurationManager.java里找到initFromCameraParameters(Camera camera)方法,改为

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

    第5步应该这样子:
    void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    previewFormat = parameters.getPreviewFormat();
    previewFormatString = parameters.get("preview-format");
    WindowManager manager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    screenResolution = new Point(width,height);
    if(width < height)
    {
    cameraResolution = getCameraResolution(parameters, new Point(height,width));
    }else{
    cameraResolution = getCameraResolution(parameters, screenResolution);
    }
    }

  • 相关阅读:
    java.sql.SQLException: 不支持的字符集 (在类路径中添加 orai18n.jar): ZHS16GBK
    STS工具各版本下载网址
    SpringBoot访问不了JSP但却能进入后台
    springboot o.a.tomcat.util.scan.StandardJarScanner : Failed to scan [file:/D:/apache-maven-3.0.5[系统找不到指定路径]
    STS工具:mybayis连接oracle数据库
    springBoot怎样访问静态资源?+静态资源简介
    springboot注解
    8.12-14 df 、mkswap、swapon、swapoff、sync
    8.5-7 mkfs、dumpe2fs、resize2fs
    8.2-3 partprobe、tune2fs
  • 原文地址:https://www.cnblogs.com/zmc/p/4704420.html
Copyright © 2011-2022 走看看