Android 绘图笔记(一)Region
来源:互联网 发布:淘宝小号信誉查询 编辑:程序博客网 时间:2024/04/30 10:01
Android Region 介绍
Region 顾名思义表示一片区域,可惜的是Canvas 内并没有直接drawRegion 这个方法。它的主要作用有两点。
- 区域和Path 之间的转换。
- Region.Op 枚举参数,表示碰撞的生成规则。(碰撞是不是更有力度)
Region构造
/** Create an empty region*/public Region() { this(nativeConstructor());}/** Return a copy of the specified region*/public Region(Region region) { this(nativeConstructor()); nativeSetRegion(mNativeRegion, region.mNativeRegion);}/** Return a region set to the specified rectangle*/public Region(Rect r) { mNativeRegion = nativeConstructor(); nativeSetRect(mNativeRegion, r.left, r.top, r.right, r.bottom);}/** Return a region set to the specified rectangle*/public Region(int left, int top, int right, int bottom) { mNativeRegion = nativeConstructor(); nativeSetRect(mNativeRegion, left, top, right, bottom);}
当然也少不了各种set 方法。
/** Set the region to the empty region*/public void setEmpty() { nativeSetRect(mNativeRegion, 0, 0, 0, 0);}/** Set the region to the specified region.*/public boolean set(Region region) { nativeSetRegion(mNativeRegion, region.mNativeRegion); return true;}/** Set the region to the specified rectangle*/public boolean set(Rect r) { return nativeSetRect(mNativeRegion, r.left, r.top, r.right, r.bottom);}/** Set the region to the specified rectangle*/public boolean set(int left, int top, int right, int bottom) { return nativeSetRect(mNativeRegion, left, top, right, bottom);}/** * Set the region to the area described by the path and clip. * Return true if the resulting region is non-empty. This produces a region * that is identical to the pixels that would be drawn by the path * (with no antialiasing). */public boolean setPath(Path path, Region clip) { return nativeSetPath(mNativeRegion, path.ni(), clip.mNativeRegion);}
重点说一下 public boolean setPath(Path path, Region clip)这个方法。 就是在Region 上利用path 进行裁剪,也就是取两者交集。不过不抗锯齿。。。。。
Region和Path 的转换
/** * Return the boundary of the region as a new Path. If the region is empty, * the path will also be empty. */public Path getBoundaryPath() { Path path = new Path(); nativeGetBoundaryPath(mNativeRegion, path.ni()); return path;}/** * Set the path to the boundary of the region. If the region is empty, the * path will also be empty. */public boolean getBoundaryPath(Path path) { return nativeGetBoundaryPath(mNativeRegion, path.ni());}
得到一个区域的path 以后。可以clip 也可以draw 。。。。
区域的碰撞
/** * Perform the specified Op on this region and the specified rect. Return * true if the result of the op is not empty. */public boolean op(Rect r, Op op) { return nativeOp(mNativeRegion, r.left, r.top, r.right, r.bottom, op.nativeInt);}/** * Perform the specified Op on this region and the specified rect. Return * true if the result of the op is not empty. */public boolean op(int left, int top, int right, int bottom, Op op) { return nativeOp(mNativeRegion, left, top, right, bottom, op.nativeInt);}/** * Perform the specified Op on this region and the specified region. Return * true if the result of the op is not empty. */public boolean op(Region region, Op op) { return op(this, region, op);}/** * Set this region to the result of performing the Op on the specified rect * and region. Return true if the result is not empty. */public boolean op(Rect rect, Region region, Op op) { return nativeOp(mNativeRegion, rect, region.mNativeRegion, op.nativeInt);}/** * Set this region to the result of performing the Op on the specified * regions. Return true if the result is not empty. */public boolean op(Region region1, Region region2, Op op) { return nativeOp(mNativeRegion, region1.mNativeRegion, region2.mNativeRegion, op.nativeInt);}
可以看到可以和Rect 碰撞,也可以和Region 碰撞。
如下是官方ApiDemo 给出的示例。
public 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;}
0 0
- Android 绘图笔记(一)Region
- Android绘图(一)
- Android 绘图(一)
- 我的android绘图学习笔记(一)
- Android绘图机制(一)
- C#用鼠标绘图笔记(一)
- 计算机绘图 学习笔记(一)
- OpenCV学习笔记(一):绘图操作
- 绘图与动画学习笔记(一)
- canvas绘图详解笔记(一)
- canvas绘图详解笔记(一)
- canvas绘图详解笔记(一)
- canvas绘图详解笔记(一)
- canvas绘图详解笔记(一)
- canvas绘图详解笔记(一)
- canvas绘图详解笔记(一)
- canvas绘图详解笔记(一)
- canvas绘图详解笔记(一)
- 深入理解Objective-C:Category(上)
- UVa 165 - Stamps
- Selenium+autoit+java 上传文件
- Android自定义控件---“取消”视图
- 客户端时间存储的取舍
- Android 绘图笔记(一)Region
- linux 环境变量设置、指令学习、日常用到的linux知识
- C++中虚析构函数的作用
- php JSON数据格式化方法
- UBI文件系统制作和挂载
- 面试频率最高的关键字——static
- Java千百问_05面向对象(009)_java的多态性都有什么表现
- android 控件 下拉刷新 SwipeRefreshLayout
- 从Node.js分裂出Io.js事件看开源软件谁做主