一直对clipRect的op参数有点迷惑,今天好好实验了一下,总结得到如下结果: 为了方便说明,把第一次clipRect的绘制范围设为A,第二次clipRect设定的范围设为B
Op.DIFFERENCE,实际上就是求得的A和B的差集范围,即A-B,只有在此范围内的绘制内容才会被显示; Op.REVERSE_DIFFERENCE,实际上就是求得的B和A的差集范围,即B-A,只有在此范围内的绘制内容才会被显示;; Op.INTERSECT,即A和B的交集范围,只有在此范围内的绘制内容才会被显示; Op.REPLACE,不论A和B的集合状况,B的范围将全部进行显示,如果和A有交集,则将覆盖A的交集范围; Op.UNION,即A和B的并集范围,即两者所包括的范围的绘制内容都会被显示; Op.XOR,A和B的补集范围,此例中即A除去B以外的范围,只有在此范围内的绘制内容才会被显示;
测试主要代码很简单如下: canvas.save(); Rect rect = new Rect(20, 20, 200, 200); canvas.clipRect(rect); Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setStyle(Style.FILL); canvas.drawRect(rect, paint); Rect clip = new Rect(100, 100, 300, 300); canvas.clipRect(clip, Op.XOR); paint.setColor(Color.BLUE); canvas.drawRect(clip, paint); canvas.restore(); canvas.save();
Rect rect = new Rect(20, 20, 200, 200);
canvas.clipRect(rect);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setStyle(Style.FILL);
canvas.drawRect(rect, paint);
Rect clip = new Rect(100, 100, 300, 300);
canvas.clipRect(clip, Op.XOR);
paint.setColor(Color.BLUE);
canvas.drawRect(clip, paint);
canvas.restore();
原地址:http://www.hotapple.org/forum.php?mod=viewthread&tid=28
|