I have a bar code image being generated by barbecue
, this image is stored in an instance of Graphics2D
.
I wanted to know how to put this image in an instance of JRDesignImage
so it can be compiled and printed.
Code
//Criar o Design do relatório
JasperDesign report = new JasperDesign();
report.setName("teste");
report.setPageWidth((int)Math.round((90 * 72) / 25.4f)); //9cm
report.setPageHeight((int)Math.round((45 * 72) / 25.4f)); //4.5cm
report.setBottomMargin(0);
report.setTopMargin(0);
report.setLeftMargin(0);
report.setRightMargin(0);
report.setColumnWidth(report.getPageWidth());
//Criar a banda de detalhes
JRDesignBand band = new JRDesignBand();
band.setHeight(report.getPageHeight());
//Criar o componente de imagem
JRDesignImage imagem = new JRDesignImage(report);
imagem.setWidth((int)Math.round((50 * 72) / 25.4f));
imagem.setHeight((int)Math.round((40 * 72) / 25.4f));
imagem.setX((int)Math.round((20 * 72) / 25.4f));
imagem.setY((int)Math.round((5 * 72) / 25.4f));
Barcode barcode = BarcodeFactory.createUPCA("91231234567");
BufferedImage image = new BufferedImage(barcode.getWidth(), barcode.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g = (Graphics2D)image.getGraphics();
g.setBackground(Color.BLUE);
barcode.draw(g, 0, 0);
Here would be the point where I would pass the image, but I have no idea how to do this, I already looked in the documentation, but I did not have any light.