我该如何迭代目录并在y轴上将每个图像堆叠在一起

时间:2018-08-03 14:26:12

标签: java

我希望能够动态加载彼此堆叠的图像,而不是静态设置图像,我想扫描目录中的png文件并在我的GenerateOneSheetBarcodes方法中使用它们-我添加了图片对于现在的情况,将不胜感激!

java文件

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();

}

图片文件

barcode_page

0 个答案:

没有答案