Java 将iText条形码图像从CCITT格式转换为PNG格式
我正在使用iText创建PDF417条形码,如下所示:Java 将iText条形码图像从CCITT格式转换为PNG格式,java,jasper-reports,itext,Java,Jasper Reports,Itext,我正在使用iText创建PDF417条形码,如下所示: 私有InputStream getBarcode()引发异常{ BarcodePDF417 barcode = new BarcodePDF417(); barcode.setText("Sample bar code text"); Image image = barcode.getImage(); image.scalePercent(50, 50 * barcode.getYHeight()); return new ByteA
私有InputStream getBarcode()引发异常{
BarcodePDF417 barcode = new BarcodePDF417();
barcode.setText("Sample bar code text");
Image image = barcode.getImage();
image.scalePercent(50, 50 * barcode.getYHeight());
return new ByteArrayInputStream(image.getRawData());
}
我需要将
barcode.getImage()
返回的CCITT格式转换为JPG、GIF或PNG格式,以便将其包含在我在JasperReports中创建的文档中。我提出的解决方案:
private Image getBarcode() throws Exception {
BarcodePDF417 barcode = new BarcodePDF417();
barcode.setText("Sample bar code text");
barcode.setAspectRatio(.25f);
return barcode.createAwtImage(Color.BLACK, Color.WHITE);
}
JasperReports支持报告中使用的图像的
java.awt.Image
类型。我提出的解决方案:
private Image getBarcode() throws Exception {
BarcodePDF417 barcode = new BarcodePDF417();
barcode.setText("Sample bar code text");
barcode.setAspectRatio(.25f);
return barcode.createAwtImage(Color.BLACK, Color.WHITE);
}
JasperReports支持报告中使用的图像的
java.awt.Image
类型。类似的东西怎么样
BarcodePDF417 barcode = new BarcodePDF417();
barcode.setText("Bla bla");
java.awt.Image img = barcode.createAwtImage(Color.BLACK, Color.WHITE);
BufferedImage outImage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
outImage.getGraphics().drawImage(img, 0, 0, null);
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
ImageIO.write(outImage, "png", bytesOut);
bytesOut.flush();
byte[] pngImageData = bytesOut.toByteArray();
FileOutputStream fos = new FileOutputStream("C://barcode.png");
fos.write( pngImageData);
fos.flush();
fos.close();
像这样的怎么样
BarcodePDF417 barcode = new BarcodePDF417();
barcode.setText("Bla bla");
java.awt.Image img = barcode.createAwtImage(Color.BLACK, Color.WHITE);
BufferedImage outImage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
outImage.getGraphics().drawImage(img, 0, 0, null);
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
ImageIO.write(outImage, "png", bytesOut);
bytesOut.flush();
byte[] pngImageData = bytesOut.toByteArray();
FileOutputStream fos = new FileOutputStream("C://barcode.png");
fos.write( pngImageData);
fos.flush();
fos.close();
谢谢你的回复。如果将来我必须转换图像,我会将您的代码示例放在手边。这次我不需要转换任何东西。谢谢你的回复。如果将来我必须转换图像,我会将您的代码示例放在手边。结果我这次不需要转换任何东西。