Scan code from android.graphics.Bitmap

Pavel
2012-11-23
2013-02-02
  • Pavel
    Pavel
    2012-11-23

    I trying to scan image from Android Gallery. I got image from gallery in Bitmap format.

    In android example class zbar.Image get bytes array with YUV encoding.
                    Image barcode = new Image(size.width, size.height, "Y800");
                    barcode.setData(data);

    I tried to convert to another format:
                    Bitmap bitmap = …
    Image qrImage = new Image( bitmap.getWidth(), bitmap.getHeight(), "JPEG" );
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress( Bitmap.CompressFormat.JPEG, 100, stream );
    byte byteArray = stream.toByteArray();
    qrImage.setData( byteArray );
                    scanner.scanImage( qrImage );
    But i get exception
    11-22 16:15:46.090: E/AndroidRuntime(8055): Caused by: java.lang.UnsupportedOperationException: unsupported image format
    11-22 16:15:46.090: E/AndroidRuntime(8055): at net.sourceforge.zbar.ImageScanner.scanImage(Native Method)
    11-22 16:15:46.090: E/AndroidRuntime(8055): at ru.itsilver.qrcodesandroid.ZBarScanner.scanImage(MyClass.java:29)

    How i can scan existing image (JPEG, PNG)?