CameraManager.java
public Rect getFramingRect()//预览区域。也就是扫面是画的那个框
public Rect getFramingRectInPreview()//扫描采集区。也就是你的扫描区
这两个方法一个设置预览框大小,一个设置实际扫描区域,把实际扫描区域弄成全屏,把扫描框自定义下大小,让用户将二维码放入识别框,这就让用户不得不拉远距离,实际上从二维码进入镜头就开始识别了,提高了识别率。下面给出调整大小的方法:
public Rect getFramingRect()
{
Point screenResolution = configManager.getScreenResolution();
if(framingRect == null)
{
if(camera == null)
{
return null;
}
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
// 控制宽高
int width = (int) (metrics.widthPixels * 0.3);
int height = (int) (width * 0.9);
// 控制位置
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;
}
/**
* 扫描识别采集区。也就是你的扫描区
* Like {@link #getFramingRect} but coordinates are in terms of the preview frame,
* not UI / screen.
*/
public Rect getFramingRectInPreview()
{
if(framingRectInPreview == null)
{
Point screenResolution = configManager.getScreenResolution();
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
// 控制宽高
int width = (int) (metrics.widthPixels * 1);
int height = (int) (metrics.heightPixels * 1);
// 控制位置
int leftOffset = (screenResolution.x - width) / 2;
int topOffset = (screenResolution.y - height) / 2;
framingRectInPreview = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
}
return framingRectInPreview;
}