在我们是Zxing框架进行二维码扫描的时候,会发现,如今手机随着分辨率的添加。那个扫描框会越来越小,在1920*1280和1280*720还算比較正常。可是三星的几款手机note4,5。S6,等几款手机分辨率高达2560*1440,甚至一些手机高达3660的吧记不清了。
在这些手机扫描的时候,弹出的扫描Activity中间SurfaceView扫描窗体小的也是醉了,
不说了解决的方法:
1:找到启动扫描的Intent 即:
Intent openCameraIntent = new Intent(context,CaptureActivity.class);
startActivityForResult(openCameraIntent,0);
2:跟进CaptureActivity类。在类中搜索:CameraManager。跟进进去CameraManager类中:最上面四行參数就是设置宽高的,
private static final int MIN_FRAME_WIDTH = (int) DP_SP_PX_Utils.dp2px(MyApplication.instance.getResources(),180); private static final int MIN_FRAME_HEIGHT = (int) DP_SP_PX_Utils.dp2px(MyApplication.instance.getResources(),180); private static final int MAX_FRAME_WIDTH = (int) DP_SP_PX_Utils.dp2px(MyApplication.instance.getResources(),240); private static final int MAX_FRAME_HEIGHT = (int) DP_SP_PX_Utils.dp2px(MyApplication.instance.getResources(),240);
第二个问题:每次扫描后图片都会压缩下
解决方法:在Zxing包下的camera包下找到CameraConfigurationManager.java类,改动:
搜索initFromCameraParameters 这种方法,在该方法下找到 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, screenResolution);
中的screenResolution改为 screenResolutionForCamera
例如以下:
- cameraResolution = getCameraResolution(parameters, screenResoluti
保存。执行完美解决,在此附上二维码扫描和二维码生成demo 不须要积分,咱们互相学习。共同跟进步,有问题能够在评论区提出。