圆扇形剪贴蒙版与Path.addArc? [英] Circular sector shaped clipping mask with Path.addArc?

查看:532
本文介绍了圆扇形剪贴蒙版与Path.addArc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建剪贴蒙版用一个扇形的形状。

I need to create a clipping mask with a shape of a circular sector.

我可以用下面的画之一:

I am able to draw one using the following:

paint.setColor(0x88FF0000);
paint.setStyle(Style.FILL);
canvas.drawArc(oval, 0, 30, true, paint);

我想用它作为一个剪辑路径,所以我尝试过:

I want to use it as a clipping path, so I've tried:

Path path = new Path();
path.addArc(oval, 0, 30);
canvas.clipPath(path, Op.REPLACE);

不过addArc不具有useCenter参数,所以我得到的是不是一个部门,而是一个片段。

However addArc doesn't have the useCenter parameter so what I get is not a sector but a segment.

推荐答案

好吧,看来也没有正确的方法使用剪贴蒙版这样做。

Ok, it seems there is no proper way doing this using a clipping mask.

不过有使用 PorterDuffXfermode 的另一种方法。见Xfermodes在ApiDemos。

However there is an alternate way using PorterDuffXfermode. See Xfermodes in ApiDemos.

我简单地画使用 drawArc A部门在我的 DST_OUT 运营商的形象。这使得包括的扇区不可见图像的一部分(未示出)。

I simply draw a sector using drawArc over my image with the DST_OUT operator. This makes the part of the image covered by the sector invisible (not drawn).

paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(0xFFFFFFFF);
paint.setStyle(Style.FILL);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));

canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
drawable.draw(canvas);
canvas.drawArc(oval, 30, 90, true, paint);

这篇关于圆扇形剪贴蒙版与Path.addArc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆