android - Barcode scan on picture from gallery -
A small idea about what steps I want to get in:
- Either take an image from the camera or select a picture from the gallery
- Load the image of the result in a
ImageView (possibly)
now Between step 1 and step 2, I want to scan barcodes on the image from step 1.
Based on the results of the scan:
- If successful,
toast
- if not, then
Toast show that there is no barcode in the image.
I have discovered ZXing (to a lesser extent) to fulfill my goal.
But what I was not able to do is:
- How to scan barcodes on the picture from the gallery?
- Scan successfully with barcode content and format information
I finally got a way of working it with Zxing Barcode Scanner Library.
While taking pictures from any saved gallery or folder, keep in mind some things,
- The image should be of good quality.
- The image should not be rotated. (This sometimes causes the problem).
- And finally, make sure that barcode scanning is supported by zxing the barcode scanner.
Here is the code.
try {bitmap bMap = bitmapfactory.decodeResource (MyActivity.this.getResources (), R.drawable.barcode_dummy / * no dummy image with barcode * /); int [] intArray = new int [bMap.getWidth () * bMap.getHeight ()]; // Copy copy pixel data from 'bitmap' intere 'array BIMAP.getpixel (intere, 0, bmap, gatewythth), 0, 0, bmapgetwidth (), bmapgatehite ()); LuminanceSource Source = New RGBLuminanceSource (bMap.getWidth), bMap.getHeight (), intArray); Binarybitmap bitmap = new binarybitmap (new hybridbenerizer (source)); Reader Reader = New Multiformat Reader (); // Use it otherwise try // checksum expansion {hashtable & lt; DecodeHintType, Object & gt; DecodeHints = new hashtable & lt; Decodheinttype, object & gt; (); decodeHints.put (decodheinttype.trY_HARDER, boolean.true); decodeHints.put (decodheint typePURE_BARCODE, boolean.true); Result result = reader.decode (bitmap, decoded); Utility. ShortshotShort (MyActivity.This, Results .getText ()); } Catch (NotFoundException e) {e.printStackTrace (); } Catch (checksum expedition e) {e.printStackTrace (); } Hold (Format Expansion E) {e.printStackTrace (); } Hold (NullPointerException e) {e.printStackTrace (); }
Hope it helps. This worked for me thanks
- if not, then
- If successful,
Comments
Post a Comment