我使用Java 8和zxing 3.3:为了测试我的Java进程,我通过合并以下几个pdf文档组成了一个大的pdf文档:
doc1.pdf + separateur.pdf + doc2.pdf + separateur.pdf + doc3.pdf.
separateur.pdf
仅包含QR码
我的Java进程必须检测到此QR码才能拆分大文档。
它工作正常...
但是在现实生活中,客户通过扫描文档来撰写pdf文件,在这种情况下,未检测到QR Code .....
此处是代码(“解码”方法无法识别扫描页面上的QR码):
if (data instanceof ImageRenderInfo) {
logger.debug("data instanceof ImageRenderInfo");
ImageRenderInfo imageRenderInfo = (ImageRenderInfo) data;
logger.debug("ImageRenderInfo ok ");
byte[] bytes = imageRenderInfo.getImage().getImageBytes();
logger.debug("bytes ok");
String pngName = coreServices.getSplitFolderTemp() +"/Page-" + currentPage[0] + "_Image-" + index + ".png";
logger.debug("pngName: " + pngName);
File image = new File(pngName);
try {
// le QR code KLINCK est stocké dans la première image de la feuille de séparation.
//if (index == 1) {
// ZXING - > Read Data from QR Code
logger.info("index: " + index);
Files.write(new File(pngName).toPath(), bytes);
logger.info("write ok");
BufferedImage bufferedImg = ImageIO.read(image);
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImg);
logger.info("source ok");
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
logger.info("bitmap ok");
Result result = new MultiFormatReader().decode(bitmap);
logger.info("decode ok");
logger.debug("result.getBarcodeFormat().toString() : " + result.getBarcodeFormat().toString());
logger.debug("result.getText().toString(): " + result.getText().toString());
if (result.getText().toString().equals("SEPARATEURZEENDOC") ||
result.getBarcodeFormat().toString().equals("DATA_MATRIX")) {
// on stocke les numéros de pages des QR Code Klinck
pageList.add(currentPage[0]);
logger.debug("QR code Klinck trouvé en page: " + currentPage[0]);
}
//}
}
catch (Exception e) {
logger.error("l'image détectée n'est pas le QR Code Klinck : " + ExceptionUtils.getStackTrace(e));
}
if (image.delete())
logger.debug("image supprimée");
}
我试图调整图像大小 (com.google.zxing.NotFoundException exception comes when core java program executed?)
通过更新这样的代码:
BufferedImage bufferedImg = ImageIO.read(image);
logger.info(bufferedImg);
BufferedImage cropedImage = bufferedImg.getSubimage(0, 0, 228, 228);
logger.info("crop ok: " + cropedImage);
LuminanceSource source = new BufferedImageLuminanceSource(cropedImage);
logger.info("source ok");
但没有任何改变。
所以我尝试使用DecodeHintType
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
logger.info("bitmap ok");
Map < DecodeHintType, Object > tmpHintsMap = new EnumMap < DecodeHintType, Object > ( DecodeHintType.class); tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
Result result = new MultiFormatReader().decode(bitmap, tmpHintsMap);
同人
我已经在日志中检索了BufferedImage对象
测试文档(有效):
BufferedImage@71b26d51: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@a91ddb2 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 228 height = 228 #numDataElements 3 dataOff[0] = 2
扫描的文档(无效):
BufferedImage@6052f653: type = 12 IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@a91ddb2 transparency = 1 transIndex = -1 has alpha = false isAlphaPre = false BytePackedRaster: width = 2542 height = 3518 #channels 1 xOff = 0 yOff = 0
我该如何解决?