【发布时间】:2012-12-23 21:32:02
【问题描述】:
我希望你能给我一些建议来解决我的问题。 我需要在一个按钮上叠加许多图像。但问题是, 这是基本图像(牙齿):(http://i.imgur.com/7tIcP.gif)
我的第一张图片是这样的: http://i.imgur.com/FYuD8.gif 然后我把这个: http://i.imgur.com/mWz9c.gif 第一张图片与第二张重叠,所以我只能看到第二张图片...
也许你会告诉我一个选项是在叠加之前更改图像的顺序,但用户会选择第一个图像,也许只是想要第一个图像,但在其他情况下,用户会放置第一个然后第二个,反之亦然...
我的代码是这样的:
BufferedImage large=null;
large = ImageIO.read(new File("firstimage.gif"));
BufferedImage small=null;
small = ImageIO.read(new File("secondimage.gif"));
int w = Math.max(large.getWidth(), small.getWidth());
int h = Math.max(large.getHeight(), small.getHeight());
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// paint both images, preserving the alpha channels
Graphics g = combined.getGraphics();
g.drawImage(large, 0, 0, null);
g.drawImage(small, 0, 0, null);
ImageIO.write(combined, "PNG", new File("twoInOne.png"));
ImageIcon icon1 = new ImageIcon(combined);
jbutton1.setIcon(icon1);
也许是图像问题的格式,或者我的代码,但我希望你们能帮助我解决这个问题,谢谢。
现在我上传了 3 张图片:我跳过了基本图片(牙齿),因为我认为这不是问题所在。
【问题讨论】:
-
为什么代码状态为 GIF 而这两个图像都是 JPG?
-
当用户想要两者时,应该会发生什么?它应该是什么样子?
-
Freezerburn 了解目标...第一个图像需要覆盖第二个图像而不覆盖第一个图像...
-
mm...我不明白...我发布的链接只是示例...我的原始图像是 .gif 格式
-
所以图像 2 中不完全透明的部分(例如蓝色/红色等)应该是半透明的?
标签: java image swing overlay jbutton