的BitmapData - 一个矩阵中的规模和选择区域?矩阵、区域、规模、BitmapData

2023-09-08 14:01:42 作者:ー克拉的眼泪

我使用了一个变换矩阵作为位图绘制的一部分,选择我的目标的一个区域,而不是从0,0图:

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 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?

推荐答案

卫生署,今天的第二个问题是我回答自己。而tx和ty属性需要由比例因子,以便相乘以preserve正确的偏移值。 presumably这是与在该矩阵转换的顺序?

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?

解决方法:

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);