博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android Zxing调整扫描区域 优化取图速度
阅读量:4574 次
发布时间:2019-06-08

本文共 2426 字,大约阅读时间需要 8 分钟。

Zxing 是google提供的二维码扫描project

Demo本身默认的扫图区域最大仅仅有 360*480    须要拉开非常远的距离才干将整个二维码扫描到

因此须要我们自己调整取图大小

 

在CameraManager.java这个类中进行调整

默认的大小是 下面这4个參数 

//  private static final int MIN_FRAME_WIDTH = 240;//  private static final int MIN_FRAME_HEIGHT = 240;//  private static final int MAX_FRAME_WIDTH = 480;//  private static final int MAX_FRAME_HEIGHT = 360;

依据屏幕大小调整      大家能够增大这些数值 : 最小的宽 高    ; 最大宽高

 

參数实际在 getFramingRect() 方法中起作用

下面是原本Demo中提供的

/**   * Calculates the framing rect which the UI should draw to show the user where to place the   * barcode. This target helps with alignment as well as forces the user to hold the device   * far enough away to ensure the image will be in focus.   *   * @return The rectangle to draw on screen in window coordinates.   */  public Rect getFramingRect() {    Point screenResolution = configManager.getScreenResolution();    if (framingRect == null) {      if (camera == null) {        return null;      }            //原生      int width = screenResolution.x * 3 / 4;      if (width < MIN_FRAME_WIDTH) {        width = MIN_FRAME_WIDTH;      } else if (width > MAX_FRAME_WIDTH) {        width = MAX_FRAME_WIDTH;      }      int height = screenResolution.y * 3 / 4;      if (height < MIN_FRAME_HEIGHT) {        height = MIN_FRAME_HEIGHT;      } else if (height > MAX_FRAME_HEIGHT) {        height = MAX_FRAME_HEIGHT;      }      int leftOffset = (screenResolution.x - width) / 2;      int topOffset = (screenResolution.y - height) / 2;      framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);      Log.d(TAG, "Calculated framing rect: " + framingRect);    }    return framingRect;  }

 

我为了适配不同的屏幕大小将代码改成了

public Rect getFramingRect() {    Point screenResolution = configManager.getScreenResolution();    if (framingRect == null) {      if (camera == null) {        return null;      }          //改动之后      int width = screenResolution.x * 7 / 10;    int height = screenResolution.y * 7 / 10;        int leftOffset = (screenResolution.x - width) / 2;    int topOffset = (screenResolution.y - height) / 3;    framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);                  Log.d(TAG, "Calculated framing rect: " + framingRect);    }    return framingRect;  }

宽高 我占领了屏幕的   7/10

当然...取图改的这么大   会多占一点内存....对应的扫描的时候快得多

 

以上是实际读取图片的大小

实际的界面美化 在ViewfinderView 这个类其中进行绘制

 

不足之处请在下方留言  谢谢

希望对您实用

资源下载地址:

转载于:https://www.cnblogs.com/mfrbuaa/p/3764371.html

你可能感兴趣的文章
Celery框架
查看>>
[c#]asp.net开发微信公众平台(4)关注事件、用户记录、回复文本消息
查看>>
[转载,感觉写的非常详细]DUBBO配置方式详解
查看>>
Android在Eclipse上的环境配置
查看>>
面向对象(五)
查看>>
android平台下使用点九PNG技术
查看>>
Python学习3,列表
查看>>
最长回文子串
查看>>
JAVA基础-JDBC(一)
查看>>
js中for和while运行速度比较
查看>>
算法第5章作业
查看>>
7.9 练习
查看>>
基于ArcGIS JS API的在线专题地图实现
查看>>
learnByWork
查看>>
lua 函数
查看>>
Git的基本命令
查看>>
四平方和
查看>>
第十八周 12.27-1.2
查看>>
C# IP地址字符串和数值转换
查看>>
TCHAR和CHAR类型的互转
查看>>