Mít Tơ Lớp Mít Tơ Lớp - 1 year ago 93
Android Question

Scan barcode from an image in gallery android

I'm creating a android project, main feature is scan barcode.

I'm tried integrate with Zxing library into my project, and it's work fine.

However, it's seems not support scan barcode from an available image in gallery of android devices.

How i can do it ? or with other barcode library ?

Please help me.

Thanks for all answers.

Answer Source

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();


To manipulate big image, please have a look at :



You could use this property android:largeHeap to increase heap size.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download