1,设置生成二维码的容错率
原来二维码在生成时并没有设置容错率,事实上我们可以简单的设置一下容错率,只需要在EncodingHandler类中hints.put(EncodeHintType.CHARACTER_SET, "utf-8");代码后 添加一行
hints.put(EncodeHintType.ERROR_CORRECTION, String.valueOf(ErrorCorrectionLevel.H));即可。
2,调整扫描框样式
扫描框的重绘方法在ViewfinderView类中的onDraw()方法中,可以在该方法中修改扫描框的显示形式。
3,调整扫描区域大小
扫描框大小由扫描区域大小限制,getFramingRect()用来获取扫描框的大小,getFramingRectInPreview()用来调整扫描区域的大小,两个方法均在CameraManager类中,getFramingRectInPreview()方法通过调用getFramingRect()来确定扫描区域的大小。
4,聚焦时间
该开源库设置了自动对焦,对焦时长默认1500毫秒,可以在AutoFocusCallback类中修改AUTOFOCUS_INTERVAL_MS参数。
5,聚焦距离
聚焦距离参数可在CameraConfigurationManager类中修改TEN_DESIRED_ZOOM参数。
6,修改切换成竖屏后图像拉伸的问题
在CameraConfigurationManager类中找到initFromCameraParameters()方法,并将一下代码重写
Camera.Parameters parameters = camera.getParameters();
previewFormat = parameters.getPreviewFormat();
previewFormatString = parameters.get("preview-format");
Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
screenResolution = new Point(display.getWidth(), display.getHeight());
Log.d(TAG, "Screen resolution: " + screenResolution);
//---修改
Point screenResolutionForCamera = new Point();
screenResolutionForCamera.x = screenResolution.x;
screenResolutionForCamera.y = screenResolution.y;
// preview size is always something like 480*320, other 320*480
if (screenResolution.x < screenResolution.y) {
screenResolutionForCamera.x = screenResolution.y;
screenResolutionForCamera.y = screenResolution.x;
}
cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
// cameraResolution = getCameraResolution(parameters, screenResolution);
Log.d(TAG, "Camera resolution: " + screenResolution);