Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating gif barcode using barcode4j

I'm trying to create barcode using barcode4j lib. This is what I've got:enter image description here And it looks smooth. This is how I do:

        BitmapCanvasProvider provider = null;


        Interleaved2Of5Bean bean = new Interleaved2Of5Bean();
        int dpi = 100;

        // Configure the barcode generator
        bean.setModuleWidth(UnitConv.in2mm(1.0f /
                                           dpi)); // makes the narrow
        // bar
        // width exactly
        // one
        // pixel

        bean.doQuietZone(false);
        provider =
                new BitmapCanvasProvider(100, BufferedImage.TYPE_BYTE_GRAY,
                                         true, 0);
        bean.generateBarcode(provider, request.getParameter("barcode"));
        provider.finish();


        BufferedImage barcodeImage = provider.getBufferedImage();
        response.setContentType("image/gif");
        OutputStream outputStream = response.getOutputStream();
        ImageIO.write(barcodeImage, "gif", outputStream);
        outputStream.close();

How to increase its difinition?

like image 823
Tony Avatar asked Mar 12 '14 07:03

Tony


People also ask

What is the difference between barcode4j and barbecue barcode library?

Barcode4j is also an open-source library. In addition, it offers 2D barcode formats – like DataMatrix and PDF417 – and more output formats. The PDF417 format is available in both libraries. But, unlike Barcode4j, Barbecue considers it a linear barcode.

What is the best barcode library for Java?

Barbecue is an open-source Java library that supports an extensive set of 1D barcode formats. Also, the barcodes can be output to PNG, GIF, JPEG, and SVG. Barcode4j is also an open-source library. In addition, it offers 2D barcode formats – like DataMatrix and PDF417 – and more output formats.

What is the difference between barcode4j and ZXing?

But, unlike Barcode4j, Barbecue considers it a linear barcode. ZXing (“zebra crossing”) is an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages.

Can I use this barcode generator with my own data?

You may use this barcode generator as part of your non-commercial web-application or web-site to create dynamic barcodes with your own data. The only condition is, that you include the text "Barcode generated with TEC-IT Barcode Software". Back-linking to www.tec-it.com is required, logos are optional.


1 Answers

Ok, I found a solution . This is how I did:

    Interleaved2Of5Bean bean = new Interleaved2Of5Bean();

    bean.setHeight(10d);

    bean.doQuietZone(false);

    OutputStream out =
        new java.io.FileOutputStream(new File("output.png"));

    BitmapCanvasProvider provider =
        new BitmapCanvasProvider(out, "image/x-png", 110,
                                 BufferedImage.TYPE_BYTE_GRAY, false,
                                 0);
    bean.generateBarcode(provider, request.getParameter("barcode"));

    provider.finish();

    BufferedImage barcodeImage = provider.getBufferedImage();
    response.setContentType("image/x-png");
    OutputStream outputStream = response.getOutputStream();
    ImageIO.write(barcodeImage, "png", outputStream);
    outputStream.close();

enter image description here

like image 175
Tony Avatar answered Sep 30 '22 11:09

Tony