【发布时间】:2013-02-27 14:28:34
【问题描述】:
我有一个跨越整个屏幕的位图,它将用作我需要绘制到画布上的 Path 对象的纹理。然后我有一个背景图像,需要在上面绘制这个纹理路径。
我尝试使用 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 模式错误吗?
【问题讨论】:
标签: android textures android-canvas porter-duff