I am having problem decoding barcode image from gallery with ZXing library. This is the code im using:
public static String decode(Bitmap bmp, Activity activity) {
String text = "";
if (bmp == null) {
Log.i("Decoding", "bitmap is null");
}
bmp = bmp.copy(Bitmap.Config.ARGB_8888, true);
int[] intArray = new int[bmp.getWidth() * bmp.getHeight()];
bmp.getPixels(intArray, 0, bmp.getWidth(), 0, 0, bmp.getWidth(),
bmp.getHeight());
LuminanceSource source = new com.google.zxing.RGBLuminanceSource(
bmp.getWidth(), bmp.getHeight(), intArray);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Reader reader = new Code128Reader();
try {
Result result = reader.decode(bitmap);
text = result.getText();
} catch (NotFoundException e) {
e.printStackTrace();
} catch (ChecksumException e) {
e.printStackTrace();
} catch (FormatException e) {
e.printStackTrace();
}
Log.i("Decoding", "done");
if (text != "")
return text;
else {
return null;
}
}
The image im trying to decode works without no problem on http://zxing.org/w/decode.jspx (https://i.stack.imgur.com/X9Atk.jpg)
but sadly not with my code. Image im trying to decode is JPEG image.
If anyone has any suggestions/fixes to my function i would be very grateful.