完美解决Android使用Zxing扫描二维码改成竖屏后,后面的预览画面出现了拉伸,扭曲的情况
第一步:找到com.zxing.camera
包下的CameraConfigurationManager.java
文件中的void initFromCameraParameters(Camera camera)
方法
第二步:在 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;
}
第三步:替换screenResolution
为screenResolutionForCamera
cameraResolution = getCameraResolution(parameters, screenResolution);
找到上边的代码替换成下边的代码(如下图)
cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
第四步:最后的修改效果为