About loading images BufferedImage in java

1

I am working on a project in java in which a form is filled out and the entered data is passed to bar codes. I already downloaded the jbarcodebean library, I already generated the first field as a barcode.

What I want to know is, How to add the other barcode fields to that same image?

This is what I have to process the barcode of the fields.

JBarcodeBean barcode = new JBarcodeBean();
//nuestro tipo de codigo de barras
barcode.setCodeType(new Interleaved25());
//valor a codificar
barcode.setCode(name);
barcode.setCheckDigit(true);
barcode.setCode(phone);
barcode.setCheckDigit(true);
BufferedImage img;
img = barcode.draw(
        new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB));
//guardar en disco como png
File file = new File("codebar.png");
try {
    ImageIO.write(img, "png", file);
} 
catch (IOException ex) {
    Logger.getLogger(Formulario_1.class.getName()).log(Level.SEVERE, null, ex);
}
    
asked by Socrasky Salamanca 23.12.2016 в 08:22
source

1 answer

0

What you are doing in the code is to set codes for your bar code, but always replace it with the last one.

barcode.setCode(name);
barcode.setCheckDigit(true);
barcode.setCode(phone);
barcode.setCheckDigit(true);

In this case I will remain as a barcode phone , it should be like this:

barcode.setCode(name + phone);

And change the type of CodeType you give, since apparently new Interleaved25 accepts only numbers, you can change it by new Code39

JBarcodeBean barcode = new JBarcodeBean();
//nuestro tipo de codigo de barras
barcode.setCodeType(new Code39());
//valor a codificar
String name = "Nicolas";
String phone = "33434";
barcode.setCode(name + " - " + phone);
barcode.setCheckDigit(true);
BufferedImage img;
img = barcode.draw(
    new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB));
//guardar en disco como png
File file = new File("codebar.png");
try {
    ImageIO.write(img, "png", file);
} catch (IOException ex) {
    System.out.println("error : " + ex.getMessage());
}

Code39

    
answered by 23.12.2016 в 16:49