I think the best is to show all of my code :)
private String processReading(BufferedImage bufferedImage) throws BarcodeReaderException {
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
com.google.zxing.datamatrix.DataMatrixReader zxingReader = new com.google.zxing.datamatrix.DataMatrixReader();
Result resultOfReading = null;
try {
Hashtable<DecodeHintType, Object> decodingHints = new Hashtable<DecodeHintType, Object>();
decodingHints.put(DecodeHintType.CHARACTER_SET, "ISO-8859-1");
decodingHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
decodingHints.put(DecodeHintType.POSSIBLE_FORMATS, Arrays.asList(BarcodeFormat.DATA_MATRIX));
resultOfReading = zxingReader.decode(bitmap, decodingHints);
} catch (NotFoundException e) {
LOG.error("ZXing error : No datamatrix found", e);
LOG.error("Please check if the image dpi is not too low");
} catch (ChecksumException e) {
LOG.error("ZXing error : Datamatrix was successfully detected and decoded, but was not returned because its checksum feature failed.", e);
LOG.error("Please check if the image dpi is not too low");
} catch (FormatException e) {
LOG.error("ZXing error :Datamatrix was successfully detected, but some aspect of the content did not conform to the barcode's format rules", e);
LOG.error("Please check if the image dpi is not too low");
}
String result = "";
try {
LOG.debug(resultOfReading.getText());
result = new String(resultOfReading.getText().getBytes("ISO-8859-1"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
During the process of this function, I have an exception "com.google.zxing.NotFoundException" with custom error message :
ERROR [main] com.lexpersona.lp2ddoc.barcode.DataMatrixReader - ZXing error : No datamatrix found
I know that it can't get the datamatrix but I wan't to understand why because the datamatrix is the only "guy" in a white page.
Is my code ok? Or do I need to do something else for xzing can get the datamatrix?
Thank you for your patience :)