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

查看:217
本文介绍了如何将多个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的建议,但当我尝试创建一个 BufferedImage NullPointerException $ c>宽24576像素,高15360像素。有什么想法吗?

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天全站免登陆