Sitemap

Wednesday, May 6, 2015

Barcode Recognition with Google's ZXing

1. Get the core and javase jars from the link below:
http://central.maven.org/maven2/com/google/zxing/

2. Create a Java method:

public class ZxingTest {
    public static void main(String[] args) throws IOException {

        File imageFile = new File("test.png");
        BufferedImage image = ImageIO.read(imageFile);

        try {
            LuminanceSource source = new BufferedImageLuminanceSource(image);

            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
            Reader reader = new MultiFormatReader();
            Result result = reader.decode(bitmap);

            System.out.println("Barcode text: " + result.getText());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

NOTE: This doesn't work for the TIFF files

Download the file Zxing.rar from the file cabinet the get the entire project.

No comments:

Post a Comment