我有一个带有盒子图标的JLabel。我在photoshop中创建图标的图像。这是一个背景完全擦除的PNG-24图像。Java - JLabel背景不完全透明?
但是,当在深色背景的顶部移动,你可以看到,背景是不完全透明:
编辑#2:
图像是透明的。我甚至通过Photoshop教程,以确保我正确地创建一个透明的图像。这个问题似乎与Java(和JLabels)有关。
我该如何解决这个问题?
我有一个带有盒子图标的JLabel。我在photoshop中创建图标的图像。这是一个背景完全擦除的PNG-24图像。Java - JLabel背景不完全透明?
但是,当在深色背景的顶部移动,你可以看到,背景是不完全透明:
编辑#2:
图像是透明的。我甚至通过Photoshop教程,以确保我正确地创建一个透明的图像。这个问题似乎与Java(和JLabels)有关。
我该如何解决这个问题?
我测试过你的图像,它不透明。当然这就是原因。
<html>
<body style="background-color:#99cccc;">
<table>
<tr>
<th>your one isn't transparent</th>
<th>this one is</th></tr>
<tr>
<td><img src="http://i.stack.imgur.com/BvYxM.png" style="border:5px solid green;"/></td>
<td><img src="http://www.axdn.com/redist/axpssp_logo.png" style="border:5px solid green;"/></td></tr>
</table>
</body>
</html>
@Gabe:粘贴到一个html文件并加载到浏览器中。这显然不是与Java有关的任何问题。
这里有一个java证明你的图像不透明,并且一个合适的透明PNG工作正常。
public static void main(String[] args) throws Throwable
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container cp = frame.getContentPane();
cp.setBackground(Color.RED);
cp.setLayout(new FlowLayout());
cp.add(new JLabel(new ImageIcon(new URL("http://i.stack.imgur.com/BvYxM.png"))));
cp.add(new JLabel(new ImageIcon(new URL("http://www.axdn.com/redist/axpssp_logo.png"))));
frame.pack();
frame.setVisible(true);
}
那我该如何解决呢?我删除所有在Photoshop中的背景?看起来像Java处理图像的方式不同。 – 2010-11-18 04:04:50
使用File/Save for Web以保存具有透明度的PNG。 – msell 2010-11-18 07:59:40
我是。确实如此。 – 2010-11-18 08:42:23
如果图像*** ***结束透明那么为什么没有出现在HTML页面透明? – pstanton 2010-11-18 22:40:31