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

前端 未结 9 1605
情书的邮戳
情书的邮戳 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:40

    try {
                    String a = textField_1.getText(); //my image path
                    InputStream barCodeInputStream = new FileInputStream(""+a);
                    BufferedImage barCodeBufferedImage = ImageIO.read(barCodeInputStream);
    
                    LuminanceSource source = new BufferedImageLuminanceSource(barCodeBufferedImage);
                    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
                    MultiFormatReader reader = new MultiFormatReader();
                    com.google.zxing.Result result = reader.decode(bitmap);
    
                    System.out.println("Barcode text is " + result.getText());
                    textField.setText(""+result.getText());
                } catch (Exception e) {
                    // TODO: handle exception
                    JOptionPane.showMessageDialog(null, "This image does not contain barcode", "Warning", JOptionPane.WARNING_MESSAGE);
                    e.printStackTrace();
                }
    

提交回复
热议问题