Zbar需要什么格式?

时间:2019-07-17 11:58:40

标签: java android format zbar

简短说明: 我正在从TextureViwe抓取一个位图。 图像格式为ARGB_8888。 我转换此图像并将其放在MainLooper中。 然后在Zbar扫描仪中找到图片。 据我所知,该扫描仪支持Gray和Y800。 我的问题是,到目前为止,所有转换尝试都失败了。我的问题是,如何设置Zbar起作用的字节数组?

我尝试了以下操作:

private byte[] getGray(Bitmap image) {
        int width = image.getWidth();
        int height = image.getHeight();

        int[] pixels = new int[height * width];
        byte grayIm[] = new byte[height * width];

        image.getPixels(pixels, 0, width, 0, 0, width, height);

        int pixel = 0;
        int count = width * height;

        while (count-- > 0) {
            int inVal = pixels[pixel];

            //Get the pixel channel values from int
            double r = (double) ((inVal & 0x00ff0000) >> 16);
            double g = (double) ((inVal & 0x0000ff00) >> 8);
            double b = (double) (inVal & 0x000000ff);

            grayIm[pixel++] = (byte) (0.2989 * r + 0.5870 * g + 0.1140 * b);
        }

        return grayIm;
    }

使用:

Image barcode = new Image(size.width, size.height, "GRAY");
barcode.setData(data);
int result = iScanner.scanImage(barcode);

或者:

ByteArrayOutputStream stream = new ByteArrayOutputStream();                  
newBitmap1.compress(Bitmap.CompressFormat.JPEG, 100, stream);
tempByteArray = stream.toByteArray();
newBitmap1.recycle();

或者:

Bitmap newBitmap1;
Bitmap.Config config = Bitmap.Config.RGB_565;
newBitmap1 = bitmap.copy(config, true);

并且:

int size = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer byteBuffer = ByteBuffer.allocate(size);
bitmap.copyPixelsToBuffer(byteBuffer);
byteArray = byteBuffer.array();

使用:

Image barcode = new Image(size.width, size.height, "RGB4");
barcode.setData(data);
int result = iScanner.scanImage(barcode.convert("Y800"));

到目前为止,我已经遇到以下错误消息:

A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0xcf491000 in tid 5810

并且:

java.lang.UnsupportedOperationException: unsupported image format

不幸的是,到目前为止我还没有进一步的想法。 我希望你能帮助我。

0 个答案:

没有答案