0

我正在开发一个安卓应用程序,它需要解码包含二维码的灰度图像。我一直在尝试将 zxing 与 android 集成。对于 rgb 色标图像,它工作正常。

对于 rgb 图像字节数组,我使用此代码构建二进制位图。

RGBLuminanceSource source = new RGBLuminanceSource(width, height, data);
BinaryBitmap Binary_bitmap = new BinaryBitmap(new HybridBinarizer(source));

但对于灰度图像,我不知道如何构建二进制位图。

4

1 回答 1

0

我只是在LuminanceSource没有 RGB 的情况下使用。尽管我使用的是缓冲图像,但适用于灰度图像。所以那将是LuminanceSource source = new BufferedImageLuminanceSource(grayscaleImg);

如果您需要将垫子转换为缓冲图像,请执行以下操作:

BufferedImage gray = new BufferedImage(mat.width(), mat.height(), BufferedImage.TYPE_BYTE_GRAY);
byte[] data = ((DataBufferByte) gray.getRaster().getDataBuffer()).getData();
mat.get(0, 0, data);
于 2016-03-23T15:44:02.503 回答