ZXING库读取PDF中的QR条形码时出错

时间:2014-10-01 14:27:35

标签: java itext zxing

我正在使用ZXING Library,使用此代码我可以在我的PDF中获取图像,具体是QR条形码,但是当我尝试在ZXING库中获取信息时......我找不到条形码。

但如果我从barocode.png这样的文件中获取相同的条形码,则效果很好。

image = ImageIO.read(new File("C:\\Workarea\\testBarcode.png"));

buffered = (BufferedImage) image;

我如何解决这个问题?是ZXING库的内部错误?我必须使用其他实现吗?

我也在测试PDFBOX,我也有同样的错误。

任何人都可以帮助我?

public void renderImage(ImageRenderInfo renderInfo) {

    BufferedImage buffered = null;          

    try {
        PdfImageObject image1 = renderInfo.getImage();

        LuminanceSource source;

        byte [] imageInByte = image1.getImageAsBytes();

        InputStream in = new ByteArrayInputStream(imageInByte);
        BufferedImage bImageFromConvert = ImageIO.read(in);

        source = new BufferedImageLuminanceSource(bImageFromConvert);

        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        Result result = new MultiFormatReader().decode(bitmap);

        ParsedResult parsedResult = ResultParser.parseResult(result);

        System.out.println(" (format: " + result.getBarcodeFormat() + ", type: " +
        parsedResult.getType() + "):\nRaw result:\n" + result.getText() + "\nParsed result:\n" +
        parsedResult.getDisplayResult());
        System.out.println("Found " + result.getResultPoints().length + " result points.");

        for (int i = 0; i < result.getResultPoints().length; i++) {
            ResultPoint rp = result.getResultPoints()[i];
            if (rp != null) {
                System.out.println(" Point " + i + ": (" + rp.getX() + ',' + rp.getY() + ')');
            }
        }
    } catch (NotFoundException ignored) {
        System.out.println("No barcode found!");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

enter image description here

enter image description here

0 个答案:

没有答案