after more than 10 hours of searching and trying I finally decided to ask here. I am using the android.hardware.camera2
library to get the image from the device camera. Now I want to automatically process the bitmap and decode a datamatrix code if there is any on the picture with the zxing library. There is a timer processing the image five times a second, and everything works well, but it doesn't recognize any datamatrix code. Until now i have the following code:
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;
}
This even does not work when replacing DataMatrixReader
with QRCodeReader
and trying it with a qr-code or trying it with MultiFormatReader
.
Every image I try to process is being decoded properly by the zxing barcode scanner app, so the problem is in the code.
I would be very happy if someone could tell me how this could work because I believe after this I'm the world champion in creatively-cursing-java ^^
Benni
P.S.: I tried every single solution in every single thread about zxing, so this really was my last choice.