我希望能够动态加载彼此堆叠的图像,而不是静态设置图像,我想扫描目录中的png文件并在我的GenerateOneSheetBarcodes方法中使用它们-我添加了图片对于现在的情况,将不胜感激!
public void GeneateOneSheetBarcodes() throws IOException
{
Image dteImage = ImageIO.read(new File ("x1.png"));
Image quantityImage = ImageIO.read(new File ("x2.png"));
BufferedImage combinedImage = new BufferedImage(
800, 800,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = combinedImage.createGraphics();
g.setBackground(Color.white);
g.clearRect(0,0, 800, 800); // This now uses the correct background color
g.drawImage(dteImage, 25, 10, null);
g.drawImage(quantityImage, 25, 100, null);
//Thread.sleep(2000);
Iterator writers = ImageIO.getImageWritersByFormatName("png");
ImageWriter writer = (ImageWriter) writers.next();
if (writer == null) {
throw new RuntimeException("PNG not supported?!");
}
ImageOutputStream out = ImageIO.createImageOutputStream(new File("c.png" ));
writer.setOutput(out);
writer.write(combinedImage);
out.close();
}