android ZXing扫描 返回崩溃问题,图像拉伸

近日使用了ZXing扫描框架,初次使用,还算上手,直接项目中运用。只是遇到两个问题,稍微常见的。
一是图像拉伸;
二是扫描完成后返回时闪退(传输大Bitmap对象导致闪退,改为Byte数组或者不传递Bitmap);
基于这两点,网友提出方案:
http://blog.csdn.net/wangshihui512/article/details/50827702(文章链接)

改动一:
CameraConfigurationManager文件
findBestPreviewSizeValue方法下边这句
int newDiff = Math.abs(newX - screenResolution.x) + Math.abs(newY - screenResolution.y);
改为
int newDiff=Math.abs(newY - screenResolution.x) + Math.abs(newX - screenResolution.y);
原文那样计算是因为计算的是横屏扫描的分辨率

这样改动后发现扫描不拉伸了,但是没有扫描结果,扫描结果返回的界面一闪而退,是因为Activity之间传递了大的Bitmap

改动二:
MipcaActivityCapture文件
handleDecode方法中将Bitmap转为Byte数组然后再在Activity之间传递或者不传递Bitmap
Intent resultIntent = new Intent();
Bundle bundle = new Bundle();
bundle.putString(“result”, resultString);
// bundle.putParcelable(“bitmap”, barcode);
// ByteArrayOutputStream baos=new ByteArrayOutputStream();
// barcode.compress(Bitmap.CompressFormat.PNG, 100, baos);
// byte [] bitmapByte =baos.toByteArray();
// bundle.putByteArray(“bitmap”,bitmapByte);
resultIntent.putExtras(bundle);
this.setResult(RESULT_OK, resultIntent);
经过这两处改动,就可以完美使用二维码了

猜你喜欢

转载自blog.csdn.net/nadeal/article/details/78048293