Android Zxing调整扫描区域 提高取图速度

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

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值