从Gallery Android中的图像扫描条形码 [英] Scan barcode from an image in gallery android
问题描述
我正在创建一个android项目,主要功能是扫描条形码.
我尝试将 Zxing 库集成到我的项目中,并且工作正常./p>
但是,似乎不支持从android设备库中的可用图像中扫描条形码.
我该怎么做?或与其他条形码库一起使用?
您可以使用此类 https://developer.android.com/training/articles/memory.html
https://developer.android.com/training/displaying- bitmaps/manage-memory.html
您可以使用此属性 android:largeHeap 增加堆大小.
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?
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();
UPDATE1
To manipulate big image, please have a look at :
https://developer.android.com/training/articles/memory.html
https://developer.android.com/training/displaying-bitmaps/manage-memory.html
You could use this property android:largeHeap to increase heap size.
这篇关于从Gallery Android中的图像扫描条形码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!