将多个BufferedImages叠加在一起? [英] Layer multiple BufferedImages on top of one another?

查看:108
本文介绍了将多个BufferedImages叠加在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个透明的 BufferedImage 个实例,我想将它们叠加在一起(也就是Photoshop图层)并烘焙成一个 BufferedImage 输出。我该怎么做?

I have multiple transparent BufferedImage instances which I'd like to layer on top of each other (aka Photoshop layers) and bake into one BufferedImage output. How do I do this?

推荐答案

我想说最好的选择是采取缓冲的图像,并创建一个额外的图像为了有一个要追加的对象。然后只需使用Graphics.drawImage()将它们放在彼此的顶部。

I would say the best bet would be to take the buffered images, and create an additional one in order to have an object to append to. Then simply use the Graphics.drawImage() to place them on top of each other.

这些内容如下:

BufferedImage a = ImageIO.read(new File(filePath, "a.png"));
BufferedImage b = ImageIO.read(new File(filePath, "b.png"));
BufferedImage c = new BufferedImage(a.getWidth(), a.getHeight(), BufferedImage.TYPE_INT_ARGB);

Graphics g = c.getGraphics();
g.drawImage(a, 0, 0, null);
g.drawImage(b, 0, 0, null);

这篇关于将多个BufferedImages叠加在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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