繁体   English   中英

透明.png背景

[英]transparent .png background

我知道我不是第一个提出此类问题的人,但我认为我的问题有所不同。

我有一个在MS Paint上绘制的png图像,它是一个播放器,当我使用图形对象绘制图像时,我希望图像的背景是透明的。 我尝试了一些带有魔术粉红色的东西,但是在Java中似乎无法正常工作。 我不是Java的新手,但是我没有经验,所以您能解释一下您使用的任何软件包或方法吗,谢谢!

  1. 您将需要使用AlphaComposite来具有透明效果:
  2. 假设您已经知道Graphics2DGraphics使用BufferedImage
  3. 创建临时图形对象g.create() ,然后处置该对象,以安全地恢复创建对象后更改的图形对象的状态。

     protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setComposite(AlphaComposite.SrcOver.derive(0.5f)); g2d.drawImage(tileImage, 0, 0, getWidth(), getHeight()); g2d.dispose(); // draw player image } 

对于Java6,应将PNG图片用于TrayIcon,但如本SO问题所述,请检查:

the background color chosen to represent the transparent pixels
the transparency options
the resolution of the icon
alternate format like SVG (provided you are using external library like Batik, and     
conversion mechnism to java.awt.Image)

暂无
暂无

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

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