BitmapData - 在一个矩阵中缩放和选择区域?
我使用变换矩阵作为位图绘制的一部分来选择目标区域,而不是从 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);
这非常有效,使用 target< 绘制
this
的内容/code> 作为边界。我还可以在绘制时使用矩阵进行缩放:
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);
当我尝试将两者合并为一个操作时,问题就出现了:
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,今天我自己回答的第二个问题。 tx 和 ty 属性需要乘以比例因子才能保留正确的偏移值。据推测这与矩阵的平移顺序有关?
解决方案:
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: