ClipRect和setClip的区别

[转]http://www.j2medev.com/bbs/dv_rss.asp?s=xhtml&boardid=11&id=4811&page=8

对于clipRect,API是这么说的:Intersects the current clip with the specified rectangle. The resulting clipping area is the intersection of the current clipping area and the specified rectangle. This method can only be used to make the current clip smaller. To set the current clip larger, use the setClip method.

大概意思是:当前裁剪与指定的矩形相交,新的裁剪区是当前裁剪区和指定矩形的交集,clipRect只能使当前裁剪区域更小,如果希望增大裁剪区域,则使用setClip.

用代码说明一下:

private void Test(Graphics g) {

//clipRect()
g.setColor(0xff0000);
g.clipRect(10, 10, 100, 100);
g.clipRect(20, 20, 100, 100);
g.fillRect(0, 0, getWidth(), getHeight());

//绘制两次设定的矩形边框
g.setClip(0, 0, getWidth(), getHeight());
g.setColor(0x0000ff);
g.drawRect(10, 10, 100, 100);
g.drawRect(20, 20, 100, 100);

//求出裁剪区域坐标和大小
clipX = g.getClipX();
clipY = g.getClipY();
clipW = g.getClipWidth();
clipH = g.getClipHeight();
print();
}

public void print(){
System.out.println("clipX:"+clipX+" clipY:"+clipY);
System.out.println("clipW:"+clipW+" clipH:"+clipH);
}

结果:

clipX:20 clipY:20

clipW:90 clipH:90

显示如下:


此主题相关图片如下001.jpg:



很容易看出,填充的是两个矩形的交集。

总结如下:

setClip() 清除之前的裁剪区,重新设定裁剪区

clipRect() 用(之前的裁剪区域)和(新的矩形区域)的交集作为新的裁剪区
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值