com.google.zxing.NotFoundException exception comes when core java program executed?

前端 未结 9 1604
情书的邮戳
情书的邮戳 2020-12-16 16:56

I have a jpeg file which has 2D bar code. Image resolution is 1593X1212. I am using xing library to decode this barcode from image. I got following code on net.



        
9条回答
  •  情话喂你
    2020-12-16 17:38

    I had the same problem. I used an image that I knew had a valid QR code and I also got the com.google.zxing.NotFoundException.

    The problem is that the image you use as a source is to large for the library to decode. After I reduced the size of my image the QR code decoder worked.

    For the purpose of my application, the QR code on the image would always be more or less in the same area, so I used the getSubimage function of the BufferedImage class to isolate the QR code.

         BufferedImage image;
         image = ImageIO.read(imageFile);
         BufferedImage cropedImage = image.getSubimage(0, 0, 914, 400);
         // using the cropedImage instead of image
         LuminanceSource source = new BufferedImageLuminanceSource(cropedImage);
         BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
         // barcode decoding
         QRCodeReader reader = new QRCodeReader();
         Result result = null;
         try 
         {
             result = reader.decode(bitmap);
         } 
         catch (ReaderException e) 
         {
             return "reader error";
         }
    

提交回复
热议问题