public function draw(containerisplayObjectContainer,targetisplayObject,w:Number=150,h:Number=200):BitmapData
{
var rect:Rectangle = target.getBounds(target);
var scale:Number = getScale(w,h);
var vw:Number = (w - target.width * scale) / 2;
var vh:Number = (h - target.height * scale) / 2;
this.samllMapBMD = new BitmapData(w,h,true,0);
var matrix:Matrix = new Matrix ;
matrix.tx -= rect.topLeft.x;
matrix.ty -= rect.topLeft.y;
matrix.scale(scale,scale);
matrix.scale(target.scaleX,target.scaleY);
matrix.tx += vw;
matrix.ty += vh;
var rect2:Rectangle = new Rectangle(0,0,w,h);
var bitmapdata:Bitmapdata = new Bitmapdata(rect2.width,rect2.height,true,0);
bitmapdata.draw(target,matrix,null,null,rect2);
return bitmapdata;
}
public function getScale(w:Number,h:Number):Number
{
var size:Number;
var scale:Number;
var num:Number = this.width - this.height;
var num2:Number = w - h;
num2 < 0 ? size = w:size = h;
num > 0 ? scale = size / this.width:scale = size / this.height;
return scale;
}
BitmapData.draw
最新推荐文章于 2020-04-08 15:48:02 发布