I'm trying to create barcode using barcode4j lib. This is what I've got: And it looks smooth. This is how I do:
 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?
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.
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.
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.
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.
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();

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With