我知道我不是第一個問這類問題的人,但我認爲地雷有點不同。透明.png背景
我有一個PNG圖像我畫MS畫圖是一個球員,我想圖像的背景是透明的,當我使用圖形對象繪製圖像。我嘗試了一些與魔法粉紅色的東西,但它似乎沒有在java中工作。我不是新來的Java,但我沒有經驗,所以你可以解釋你使用的任何軟件包或方法,謝謝!
我知道我不是第一個問這類問題的人,但我認爲地雷有點不同。透明.png背景
我有一個PNG圖像我畫MS畫圖是一個球員,我想圖像的背景是透明的,當我使用圖形對象繪製圖像。我嘗試了一些與魔法粉紅色的東西,但它似乎沒有在java中工作。我不是新來的Java,但我沒有經驗,所以你可以解釋你使用的任何軟件包或方法,謝謝!
用的Java6,一個PNG圖像應該用於任務欄圖標,但在這太問題提到,檢查:
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)
AlphaComposite
有透明效果:Graphics2D
和Graphics
使用BufferedImage
創建臨時圖形對象g.create()
然後處置對象以安全恢復狀態o f圖形對象在創建對象後發生更改。
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
}
是背景圖像和影像播放兩個不同的形象? – Sage
是的,我喜歡地板磚,然後我在上面畫着玩家形象,所以你看到他周圍的地板。 – Acor74u
下面給出了一個答案。檢查 – Sage