8
我有佔據整個屏幕的背景圖像。我在背景上繪製畫布,並將其顏色設置爲白色,以便您看不到圖像。我想要實現的是在白色畫布上繪製透明形狀,並通過背景圖像顯示該形狀的位置。我正在使用SurfaceView並執行SurfaceView.Callback
。在畫布上繪製透明形狀
我有佔據整個屏幕的背景圖像。我在背景上繪製畫布,並將其顏色設置爲白色,以便您看不到圖像。我想要實現的是在白色畫布上繪製透明形狀,並通過背景圖像顯示該形狀的位置。我正在使用SurfaceView並執行SurfaceView.Callback
。在畫布上繪製透明形狀
你應該讓白色透明:
public void draw(Canvas canvas)
{
final RectF rectF = new RectF();
final Paint paint = new Paint();
paint.setARGB(128, 255, 255, 255);
rectF.set(0,0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawRect(rectF, paint);
}
繪製透明形狀遵循這個代碼
Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
//draw any shape, here I am drawing Rect shape
Rect rect=new Rect(left, top, right, bottom);
canvas.drawRect(rect,paint);
它離開該地區黑 – 2017-02-26 18:35:20