getRect()方法返回的矩形大小是不把笔触大小算进去的,而getBounds()方法返回的矩形大小把笔触大小算进去,因此getBounds() 返回的矩形面积 >= getRect() 返回的矩形面积
代码如下:
import flash.display.CapsStyle;
import flash.display.JointStyle;
import flash.display.LineScaleMode;
import flash.display.Sprite;
import flash.geom.Rectangle;
var triangle:Sprite = new Sprite();
var color:uint = 0xFF0044;
var wid:Number = 20;
var al:Number = 1.0;
var pixelHinting:Boolean = true;
var scaleMode:String = LineScaleMode.NORMAL;
var caps:String = CapsStyle.SQUARE;
var joints:String = JointStyle.MITER;
triangle.graphics.lineStyle(wid, color, al, pixelHinting, scaleMode, caps, joints);
var triangleSide:Number = 100;
triangle.graphics.moveTo(0, 0);
triangle.graphics.lineTo(0, triangleSide);
triangle.graphics.lineTo(triangleSide, triangleSide);
triangle.graphics.lineTo(0, 0);
var rect:Rectangle = triangle.getRect(this);
var bound:Rectangle = triangle.getBounds(this);
triangle.graphics.lineStyle(0,0x00ff00);
triangle.graphics.drawRect(rect.x,rect.y,rect.width,rect.height);
triangle.graphics.lineStyle(0,0xff0000);
triangle.graphics.drawRect(bound.x,bound.y,bound.width,bound.height);
addChild(triangle);
trace(bound); // (x=-10, y=-24.1, w=134.10000000000002, h=134.1)
trace(rect); // (x=0, y=0, w=100, h=100)
运行截图:
![](https://i-blog.csdnimg.cn/blog_migrate/5851c7d41e2e58a61439813f2a964a60.jpeg)