Region.Op

来源:互联网 发布:tensorflow dropout 编辑:程序博客网 时间:2024/04/27 15:54

1. 裁剪注意

在Android自定义View使用绘图的裁剪功能的时候,我们最好manifest中的<application/> 或者<activity/>或者<fragment/>标签中添加如下属性:

android:hardwareAccelerated="false"

因为裁剪功能是不支持硬件加速的.没有设置的话,有可能绘图裁剪的效果出不来.

2.裁剪枚举类型

android原生api裁剪方法中clipRectclipPath方法中,有的不传递Region.Op参数,其实在它的内部默认是Region.Op.INTERSECT. 这点可以查看他们的api可知:

public boolean clipRect(@NonNull RectF rect) {    return native_clipRect(mNativeCanvasWrapper, rect.left, rect.top, rect.right, rect.bottom,            Region.Op.INTERSECT.nativeInt);}
public boolean clipPath(@NonNull Path path) {    return clipPath(path, Region.Op.INTERSECT);}
// the native values for these must match up with the enum in SkRegion.hpublic enum Op {    DIFFERENCE(0),    INTERSECT(1),    UNION(2),    XOR(3),    REVERSE_DIFFERENCE(4),    REPLACE(5);    Op(int nativeInt) {        this.nativeInt = nativeInt;    }    /**     * @hide     */    public final int nativeInt;}

3. 裁剪参数解析

那么他们什么含义呢? 形象的举个例子

A:表示第一个裁剪的形状;
B:表示第二次裁剪的形状;

  • Region.Op.DIFFERENCE :是A形状中不同于B的部分显示出来

  • Region.Op.REPLACE:是只显示B的形状

  • Region.Op.REVERSE_DIFFERENCE :是B形状中不同于A的部分显示出来,这是没有设置时候默认的

  • Region.Op.INTERSECT:是A和B交集的形状

  • Region.Op.UNION:是A和B的全集

  • Region.Op.XOR:是全集形状减去交集形状之后的部分

4. 代码示例

http://blog.csdn.net/eyishion/article/details/53728913