Search code examples
javabarcodeean-13

Java. BarCode Ean-13 to String


I have a project, that draws a price tag, which has a barcode in it. To draw a barcode i use a JLabel with EAN-13 font set in. The input data, from which the price tag is generated, consists of two barcode attributes: the barcode number

080432402184 for example

and the encoded version, which is passed to the previosly mentioned JLabel

!h04324|PRQXTp for that barcode number

The problem is that i dont have access to the code, which generates the encoded version, and the algorithm that generates it has bugs. Because of that i want to write that thing from scrap, but having trouble finding the encoding algorithm.

Can someone point me to where i can find instructions on encoding it? Thanks.

=======================================================================

The Barcode4J problem. Trying to create a Graphics2D object and draw a barcode on it(cant really use a file out, because the barcode is only a part of the price tag).

Trying to do this using Java2DCanvasProvider:

EAN13Bean bean = new EAN13Bean();

    final int dpi = 150;

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

    bean.setHeight(chart.getBarcodeMainHeight()-10);
    bean.setFontSize(10f);

    BufferedImage bi = new BufferedImage(chart.getBarcodeMainWidth(), chart.getBarcodeMainHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = bi.createGraphics();

    //graphics.fillRect(0, 0, chart.getBarcodeMainWidth(), chart.getBarcodeMainHeight());
    Java2DCanvasProvider canv = new Java2DCanvasProvider(graphics, 0);

    bean.generateBarcode(canv, priceTag.getBarCodeNumber());

    barCodeLabel.setIcon(new ImageIcon(bi));

but i recieve an inverted image block(i'm really new to Graphics2D).


Solution

  • Barcode4J has your back on this. It can also generate the images, so you can let go of the JLabel and the special font.