Closed CoXier closed 8 years ago
Recently I have a difficulty using zxing to decode bitmap. I search solutions on Internet and I have tried some of them.Here is my try:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.qrcode); String result = DecodeUtils.decodeWithZxing(bitmap);
R.drawable.qrcode is a .jpg file.
R.drawable.qrcode
.jpg
And BarCodeUtil.java is:
BarCodeUtil.java
public static String decodeWithZxing(Bitmap bitmap) { MultiFormatReader multiFormatReader = new MultiFormatReader(); Map<DecodeHintType, Object> hints = new Hashtable<>(); hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE); multiFormatReader.setHints(hints); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); Result rawResult = null; RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels); if (source != null) { BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source)); try { rawResult = multiFormatReader.decodeWithState(binaryBitmap); } catch (ReaderException re) { re.printStackTrace(); } finally { multiFormatReader.reset(); } } return rawResult != null ? rawResult.getText() : null; }
But when I run the above code,I got a exception:
com.google.zxing.NotFoundException
So I search the exception,someone think bitmap size causes this exception.Then I resize the bitmap size:
BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inSampleSize = 4; Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.zhifubao,options); String result = DecodeUtils.decodeWithZxing(bitmap)
But it still does not work for me.
Is there a good solution to decode bitmap with a qrcode?
Please don't ask questions here. Use the mailing list. It's not clear what you're asking; it's normal to get NotFoundException in some images. Maybe consider TRY_HARDER or PURE_BARCODE mode.
I am sorry for that!
Recently I have a difficulty using zxing to decode bitmap. I search solutions on Internet and I have tried some of them.Here is my try:
R.drawable.qrcode
is a.jpg
file.And
BarCodeUtil.java
is:But when I run the above code,I got a exception:
So I search the exception,someone think bitmap size causes this exception.Then I resize the bitmap size:
But it still does not work for me.
Is there a good solution to decode bitmap with a qrcode?