BitmapData - 在一个矩阵中缩放和选择区域?

发布于 2024-11-17 14:15:59 字数 852 浏览 4 评论 0原文

我使用变换矩阵作为位图绘制的一部分来选择目标区域,而不是从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回忆那么伤 2024-11-24 14:15:59

哦,今天我自己回答的第二个问题。 tx 和 ty 属性需要乘以比例因子才能保留正确的偏移值。据推测这与矩阵的平移顺序有关?

解决方案:

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文