开发者

BitmapData - scale and select area in one matrix?

I'm using a transform matrix as part of a bitmap draw to select an area of my target rather than drawing from 0,0:

var bmd:BitmapData = new BitmapData(target.width,target.height,true,0);
var mat:Matrix = new Matrix(1,0,0,1,-target.x,-target.y);
bmd.draw(this,mat);

This works perfectly, drawing the contents of this using target as a boundary. I can also use a matrix to scale as 开发者_JS百科I draw like this:

var scale:Number = .32;
var bmd:BitmapData = new BitmapData(target.width/scale,target.height/scale,true,0);
var mat:Matrix = new Matrix(scale,0,0,scale);
bmd.draw(this,mat);

The problem comes when I try to combine the two into one operation:

var scale:Number = .32;
var bmd:BitmapData = new BitmapData(target.width/scale,target.height/scale,true,0);
var mat:Matrix = new Matrix(scale,0,0,scale,-target.x,-target.y);
bmd.draw(this,mat);

I'm not sure what's going wrong here, but when this is added to the stage as a bitmap nothing shows up, but if I only do one operation or the other they both work as expected. Any ideas?


Doh, second question today that I'm answering myself. The tx and ty properties need to be multiplied by the scale factor in order to preserve the correct offset values. Presumably this is something to do with the order in which the matrix is translated?

Solution:

var scale:Number = .32;
var bmd:BitmapData = new BitmapData(target.width/scale,target.height/scale,true,0);
var mat:Matrix = new Matrix(scale,0,0,scale,-(target.x*scale),-(target.y*scale));
bmd.draw(this,mat);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜