【发布时间】:2015-10-27 12:56:50
【问题描述】:
经过10多个小时的搜索和尝试,我终于决定在这里问。我正在使用android.hardware.camera2 库从设备摄像头获取图像。现在我想使用 zxing 库自动处理位图并解码数据矩阵代码(如果图片上有任何代码)。有一个计时器每秒处理五次图像,一切正常,但它不识别任何数据矩阵代码。到目前为止,我有以下代码:
public String readDataMatrix(Bitmap bitmap) {
int width = bitmap.getWidth(),
height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
BinaryBitmap bBitmap = new BinaryBitmap(new HybridBinarizer(source));
DataMatrixReader reader = new DataMatrixReader();
Result rawResult = null;
try {
rawResult = reader.decode(bBitmap);
String result = reader.decode(bBitmap).getText();
return result;
} catch (NotFoundException | ChecksumException | FormatException e) {
e.printStackTrace();
}
if (rawResult != null) {
Log.i(TAG, "==============================================");
Log.i(TAG, rawResult.getText());
Log.i(TAG, "==============================================");
}
return rawResult != null ? rawResult.getText() : null;
}
当用QRCodeReader 替换DataMatrixReader 并用二维码尝试或用MultiFormatReader 尝试时,这甚至不起作用。
我尝试处理的每张图像都被 zxing 条码扫描仪应用程序正确解码,所以问题出在代码中。
如果有人能告诉我这是如何工作的,我会非常高兴,因为我相信在此之后我是 creative-cursing-java 的世界冠军^^
本尼
P.S.:我在每个关于 zxing 的线程中都尝试了每个解决方案,所以这确实是我最后的选择。
【问题讨论】:
标签: java android zxing decoding datamatrix