2013-02-27 35 views
0

我有一個跨越整個屏幕的位圖,它將用作我需要繪製到畫布的Path對象的紋理。然後我有一個背景圖像,這個紋理路徑需要在上面繪製。Android - 將位圖紋理應用到API繪圖例程

我嘗試使用PorterDuff模式,但似乎沒有任何工作正常。我很難搞清楚PorterDuff模式究竟是如何運作的,因爲他們似乎都沒有像I always thought they were supposed to function那樣行事。

我已經找到了一種方法來紋理這個測試代碼路徑:

Paint paint = new Paint(); 
    //draw the texture 
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.texture),0,0,paint); 
    //construct the Path with an inverse even-odd fill 
Path p = new Path(); 
p.setFillType(Path.FillType.INVERSE_EVEN_ODD); 
p.addCircle(this.getHeight()/2, this.getWidth()/2, 200, Path.Direction.CCW); 
    //use CLEAR to remove inverted fill, thus showing only the originally filled section 
paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR)); 
    //draw path 
canvas.drawPath(p, paint); 

但我無法弄清楚如何再放置上一個背景圖像的頂部。我只是使用PorterDuff模式錯了嗎?

回答

0

也許我的問題,可能會導致你到你的解決方案:

應用於您的通話drawPathpaint
什麼是塗料的風格?
什麼是描邊寬度?
什麼是描邊/填充顏色?

如果您沒有使用衝調/填充顏色,而是使用紋理,請調用塗料的setShader(使用BitmapShader)?

+0

樣式是填充,這是唯一重要的部分,因爲您不應該看到填充顏色或筆劃。我會使用BitmapShader,但我不知道有任何方法可以修改紋理的座標以按照我希望的方式對齊它。有沒有我不知道的方法? – Taw 2013-02-27 15:26:25