在我們是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 不須要積分,咱們互相學習。共同跟進步,有問題能夠在評論區提出。
