解决Android二维码扫描ZXing竖屏拉伸变长闪退问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/generallizhong/article/details/78717562

用二维码的话会出现竖屏扫描图像拉伸变长的问题,解决拉伸变长的问题后又会出现闪退的问题(传输大Bitmap对象导致扫描后直接闪退,改为Byte数组或者不传递Bitmap)

只改动两个地方就能搞定了:

第一个地方:

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);
之前那种方式是为了计算横屏的分辨率,改动后扫描图片倒正常了,就是扫描后会出现闪退,
第二个地方:
MipcaActivityCapture文件中handleDecode(Result result, Bitmap barcode)方法里else里改为以下代码
 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/generallizhong/article/details/78717562