2013-11-25 807 views
0

我知道我不是第一個問這類問題的人,但我認爲地雷有點不同。透明.png背景

我有一個PNG圖像我畫MS畫圖是一個球員,我想圖像的背景是透明的,當我使用圖形對象繪製圖像。我嘗試了一些與魔法粉紅色的東西,但它似乎沒有在java中工作。我不是新來的Java,但我沒有經驗,所以你可以解釋你使用的任何軟件包或方法,謝謝!

+0

是背景圖像和影像播放兩個不同的形象? – Sage

+0

是的,我喜歡地板磚,然後我在上面畫着玩家形象,所以你看到他周圍的地板。 – Acor74u

+0

下面給出了一個答案。檢查 – Sage

回答

0

用的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) 
1
  1. 您將需要使用AlphaComposite有透明效果:
  2. 假設你已經知道Graphics2DGraphics使用BufferedImage
  3. 創建臨時圖形對象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 
    
    } 
    
+0

setcomposite()和derive()方法做了什麼? – Acor74u

+0

'Graphics2D.setComposite'設置我們傳入的組合。'AlphaComposite.SrcOver.derive(alpha)'返回一個使用指定alpha值的相似AlphaComposite對象。我添加了Class文檔的鏈接。請檢查他們的詳細信息 – Sage

+0

好的,謝謝!對不起,我不能滿足你的答案 – Acor74u