BitmapData.draw ClipRect 未按预期工作
我有一个包含 4 层的组件:(按深度升序)bgImage:Sprite、dropZone:Sprite、dropMask:Sprite 和 line:Sprite。 bgImage位于0,0,其他对象放置在各个正坐标处。 dropMask 正在屏蔽 dropZone。
在位图捕获时,我只想从 dropZone 和 dropMask 图层进行绘制,因此我尝试这样做:
removeChild(bgImage);
removeChild(line);
var bmd:BitmapData = new BitmapData(dropMask.width,dropMask.height,true,0);
bmd.draw(this,null,null,null,dropMask.getBounds(this));
尽管 dropMask 位于 50,60,但捕获始终从 0,0 开始。我也尝试过获取边界矩形并强制 x,y,但这没有什么区别。我在这里做错了什么,我应该忘记clipRect并使用矩阵来代替吗?
I have a component that contains 4 layers: (in ascending depth order) bgImage:Sprite, dropZone:Sprite, dropMask:Sprite and line:Sprite. The bgImage is at 0,0, and the other objects are placed at various positive coordinates. dropMask is masking dropZone.
At the point of bitmap capture I want to only draw from the dropZone and dropMask layers, so I'm trying this:
removeChild(bgImage);
removeChild(line);
var bmd:BitmapData = new BitmapData(dropMask.width,dropMask.height,true,0);
bmd.draw(this,null,null,null,dropMask.getBounds(this));
Despite the dropMask being located at 50,60 the capture always starts from 0,0. I've also tried getting the boundary rectangle and forcing the x,y, but it makes no difference. What am I doing wrong here, and should I just forget clipRect and use a matrix instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个常见的例程:
解决方案步骤:
矩形
。-rectangle.x
转换它,-rectangle.y
draw()
调用中使用该矩阵。在步骤 1 中,您甚至可能会遇到类似的情况:
当我编写使用大量绘图剪辑的代码时,我创建一个矩阵并每次重用它,执行
matrix.identity();
来重置变换。无需为每个绘图创建新的矩阵。编辑 不,clipRect 在这里没有帮助。仅当您想要部分绘制某些内容而不是整个剪辑时才使用它。
A common routine for that:
Solution steps:
rectangle
in coordinate space of what you are going to draw.-rectangle.x
,-rectangle.y
draw()
call.In step 1 you may even encounter something like that:
When I code something that uses a lot of drawing clips, I create a matrix and reuse it each time, doing
matrix.identity();
to reset transforms. No need to create new matrix for each drawing.EDIT And no, clipRect doesn't help here. You use it only when you want to draw somthing partially, not the whole clip.
没关系,我误解了clipRect的目的。 http://pixelwelders.com/blog/actionscript-3/2008/ as3-bitmapdata-foibles/.使用矩阵很容易并且可以解决问题。
Nevermind, I've misunderstood the purpose of clipRect. http://pixelwelders.com/blog/actionscript-3/2008/as3-bitmapdata-foibles/. Using a matrix for this is easy and solves the problem.