简体   繁体   English

保留BufferedImage.setRGB()中的alpha值?

[英]Preserving alpha values in BufferedImage.setRGB()?

I'd like to composite a few images together. 我想将一些图像合成在一起。 Each image has some transparency to it. 每个图像都有一定的透明度。 I'm trying to use BufferedImage for this but there doesn't seem to be any way to use it for this purpose? 我正在尝试为此使用BufferedImage,但似乎没有任何方法可用于此目的?

We only get the BufferedImage.setRGB() method. 我们只得到BufferedImage.setRGB()方法。 Instead I need something where transparent pixels won't overwrite the pixel values below them. 相反,我需要透明像素不会覆盖其下方像素值的东西。 How can I go about doing that? 我该怎么做呢?

Thanks 谢谢

/* imageType should be one of the variants that includes alpha  */
final BufferedImage composited = new BufferedImage(width, height, imageType);
final Graphics graphics = composited.getGraphics();
for (final Image layer : layers) {
  /* draw the image at 0,0 */
  graphics.drawImage(layer, 0, 0, null);
}
graphics.dispose();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM