如何将多个 PNG 组合成一个大的 PNG 文件? [英] How to combine multiple PNGs into one big PNG file?

查看:62
本文介绍了如何将多个 PNG 组合成一个大的 PNG 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约.6000 个 PNG 文件(256*256 像素),并希望以编程方式将它们组合成一个大的 PNG 文件.

I have approx. 6000 PNG files (256*256 pixels) and want to combine them into a big PNG holding all of them programmatically.

最好/最快的方法是什么?

What's the best/fastest way to do that?

(目的是在纸上打印,所以使用一些网络技术不是一种选择,拥有一个单一的图片文件将消除许多使用错误.)

(The purpose is printing on paper, so using some web-technology is not an option and having one, single picture file will eliminate many usage errors.)

我尝试了 fahd 的建议,但是当我尝试创建一个宽度为 24576 像素、高度为 15360 像素的 BufferedImage 时,我得到了一个 NullPointerException.有什么想法吗?

I tried fahd's suggestion but I get a NullPointerException when I try to create a BufferedImage with 24576 pixels wide and 15360 pixels high. Any ideas?

推荐答案

创建您要写入的大图像.根据您想要的行数和列数计算其尺寸.

Create a large image which you will write to. Work out its dimensions based on how many rows and columns you want.

    BufferedImage result = new BufferedImage(
                               width, height, //work these out
                               BufferedImage.TYPE_INT_RGB);
    Graphics g = result.getGraphics();

现在遍历您的图像并绘制它们:

Now loop through your images and draw them:

    for(String image : images){
        BufferedImage bi = ImageIO.read(new File(image));
        g.drawImage(bi, x, y, null);
        x += 256;
        if(x > result.getWidth()){
            x = 0;
            y += bi.getHeight();
        }
    }

最后写到文件中:

    ImageIO.write(result,"png",new File("result.png"));

这篇关于如何将多个 PNG 组合成一个大的 PNG 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆