demo下载地址:http://download.csdn.net/detail/wdd1324/9824100
==============================================================
1-出现闪退的问题(传输大Bitmap对象导致闪退,改为Byte数组或者不传递Bitmap)
2-对于ZXing扫描来说,实际图片的大小就是屏幕的大小,所以我们要从好几组预览图片的尺寸中找到一组最合适的,这样预览的图片就不会变形了。
对应的代码如下:
com.mining.app.zxing.camera.CameraConfigurationManag
private static Point findBestPreviewSizeValue
//
加黑的部分就是重点,找到缩放比例最合适的一个。
3-解决方法:
1.在DecodeHandler.java中,修改decode方法
PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(data, width, height);
为
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width; // Here we are swapping, that's the difference to #11
width = height;
height = tmp;
PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(rotatedData, width, height);
2.在CameraManager.java中,注释代码:
// rect.left = rect.left * cameraResolution.x / screenResolution.x;
// rect.right = rect.right * cameraResolution.x / screenResolution.x;
// rect.top = rect.top * cameraResolution.y / screenResolution.y;
// rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;
修改为
rect.left = rect.left * cameraResolution.y / screenResolution.x;
rect.right = rect.right * cameraResolution.y / screenResolution.x;
rect.top = rect.top * cameraResolution.x / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
3.在CameraConfigurationManager.java中,在setDesiredCameraParameters方法中添加一句
camera.setDisplayOrientation(90);
4.在AndroidManifest.xml中,把Activity的属性android:screenOrientation="landscape"
改为
android:screenOrientation="portrait"
编译运行即可!
参考博客:
http://www.cnblogs.com/SZ2015/p/4750779.html
http://jingyan.baidu.com/article/c843ea0ba83d0677921e4a52.html
http://m.blog.csdn.net/article/details?id=51683125
-----------------------------------------------
http://blog.csdn.net/sunmanzth/article/details/6860157
http://www.cnblogs.com/moka/archive/2013/05/24/3096937.html
http://blog.sina.com.cn/s/blog_8a86f4dd0102whf2.html
http://lishuaishuai.iteye.com/blog/2324332