Tuesday, 13 December 2016

Scan barcode from an image in gallery android


Scan barcode from an image in gallery android


You could use this class MultiFormatReader from ZXing library.


You have to get Gallery image in BitMap and convert it as this
Bitmap bMap = [...];
String contents = null;

int[] intArray = new int[bMap.getWidth()*bMap.getHeight()]; 
//copy pixel data from the Bitmap into the 'intArray' array 
bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight()); 

LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(), intArray);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

Reader reader = new MultiFormatReader();
Result result = reader.decode(bitmap);
contents = result.getText();

No comments:

Post a Comment