My test case is very simple: I'm generating a data matrix code and then I want to read it again. Both with xzing vs3.0.0. I'm doing this the same way with qr-code and pdf417 - and it works perfectly.
This is my code:
@Test
public void testDataMatrix() throws Exception {
writeDataMatrix();
String result = readDataMatrix("out/data_matrix.png", "UTF-8", new EnumMap<DecodeHintType, Object>(DecodeHintType.class));
assertEquals("my message", result);
}
public static void writeDataMatrix() throws IOException {
DataMatrixWriter writer = new DataMatrixWriter();
BitMatrix matrix = writer.encode("my message", BarcodeFormat.DATA_MATRIX, 100, 100);
MatrixToImageWriter.writeToPath(matrix, "PNG", Paths.get("out/data_matrix.png"));
}
public static String readDataMatrix(String filePath, String charset, Map hintMap)
throws FileNotFoundException, IOException, NotFoundException {
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
new BufferedImageLuminanceSource(
ImageIO.read(new FileInputStream(filePath)))));
Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap,
hintMap);
return qrCodeResult.getText();
}
If I run the test above, a data matrix image will be generated in out. This file is readable by the xzing online reader. But it works not in my own code:
com.google.zxing.NotFoundException
Any ideas? Thanks in advance.