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() 用(之前的裁剪区域)和(新的矩形区域)的交集作为新的裁剪区

你可能感兴趣的:(XHTML,asp,bbs)