我做了个二维码扫描功能,需要从本地图库得到一张二维码图片进行解析,但是总是报NotFoundException。不知道是什么原因,求大神们帮帮忙!万分感激!
代码如下:
ContentResolver cr = this.getContentResolver();
Bitmap photo = null;
Bitmap bmap=null;
try {
photo = BitmapFactory.decodeStream(cr.openInputStream(data
.getData()));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
bmap=comp(photo);       //对图片进行压缩处理
 
 if(bmap!=null){
Map<DecodeHintType, Object> hints = new HashMap<DecodeHintType, Object>();
hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); RGBLuminanceSource source = new RGBLuminanceSource(bmap);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
Result result;
try {
result = reader.decode(bitmap1, hints);
System.out.println("res:》》》》》》》:" + result.getText());
Intent in = getIntent();
in.putExtra("message", result.getText());
setResult(Activity.RESULT_OK, in);
finish();
} catch (NotFoundException e) {     //出现异常处
e.printStackTrace();
Log.i("错误","错误");

catch (ChecksumException e) {
e.printStackTrace();
} catch (FormatException e) {
e.printStackTrace();
}二维码图片