2010-11-18 107 views
2

我有一个带有盒子图标的JLabel。我在photoshop中创建图标的图像。这是一个背景完全擦除的PNG-24图像。Java - JLabel背景不完全透明?

但是,当在深色背景的顶部移动,你可以看到,背景是不完全透明:

image


编辑#2:

图像是透明的。我甚至通过Photoshop教程,以确保我正确地创建一个透明的图像。这个问题似乎与Java(和JLabels)有关。

我该如何解决这个问题?

+0

如果图像*** ***结束透明那么为什么没有出现在HTML页面透明? – pstanton 2010-11-18 22:40:31

回答

4

我测试过你的图像,它不透明。当然这就是原因。

<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); 
} 
+0

那我该如何解决呢?我删除所有在Photoshop中的背景?看起来像Java处理图像的方式不同。 – 2010-11-18 04:04:50

+0

使用File/Save for Web以保存具有透明度的PNG。 – msell 2010-11-18 07:59:40

+0

我是。确实如此。 – 2010-11-18 08:42:23

1

您可以尝试使用GIF格式并相应地设置alpha值。 我目前无法看到您的图片。 那么,确保你创建的图像是透明的。 否则,你不会得到它,因为你需要。

制作透明图像样品指导:LINK

+0

这也没有效果。我知道它必须是一个PNG。 (我以前读过Java的透明文件只能用于PNG。) – 2010-11-18 07:08:53

+0

嘿....我想我在这里遇到了同样的事情。 一旦我的PNG显示OK,但是当我重新绘制它时,它也给我黑色背景......那么,如何修复它? :( – gumuruh 2011-08-09 03:47:46