还是这个接手项目,二维码扫描集成的是zxing,扫描界面的图像有明显的拉伸变形。
这种问题,根据以往的经验,一般是x,y轴错位引起的,处理好x,y轴的问题,一般可以解决问题。
由于这个问题,之前有很多人遇到,并分享在网上了,所以,我这里也就不需要重复造轮子了。
这里看了一篇博客:Android Zxing二维码扫描图片拉伸,用了上面的办法,
成功的解决图片拉伸问题。
解决方法如下:
修改CameraConfigurationManager.Java里面的initFromCameraParameters方法:
void initFromCameraParameters(Camera camera) { 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); //added 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); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。