九宫切割

function reslice():void
{
var bmpData:BitmapData = new BitmapData(_width, _height, true, 0x0);
var rows:Array = [0, _slicingRect.top, _slicingRect.bottom, _oriBitmap.height];
var cols:Array = [0, _slicingRect.left, _slicingRect.right, _oriBitmap.width];

var dRows:Array = [0, _slicingRect.top, _height-(_oriBitmap.height-_slicingRect.bottom), _height];
var dCols:Array = [0, _slicingRect.left, _width-(_oriBitmap.width-_slicingRect.right), _width];
var origin:Rectangle;
var draw:Rectangle;
var mat:Matrix = new Matrix();
bmpData.lock();
for (var cx:int=0;cx<3;cx++)
{
for (var cy:int=0;cy<3;cy++)
{
origin = new Rectangle(cols[cx], rows[cy], cols[cx+1]-cols[cx], rows[cy+1]-rows[cy]);
draw = new Rectangle(dCols[cx], dRows[cy], dCols[cx+1]-dCols[cx], dRows[cy+1]-dRows[cy]);

mat.identity();

mat.a = draw.width/origin.width;
mat.d = draw.height/origin.height;

mat.tx = draw.x-origin.x*mat.a;
mat.ty = draw.y-origin.y*mat.d;

bmpData.draw(_oriBitmap, mat, null, null, draw, smoothing);
}
}
bmpData.unlock();
if (this.bitmapData)
this.bitmapData.dispose();

this.bitmapData = bmpData;
}

你可能感兴趣的:(九宫切割)