从包含透明区域和效果区域的displayObject获取BitmapData
我有这个功能:
public static function cloneDpObj(target:DisplayObject):Bitmap
{
var duplicate:Bitmap;
var tBitData:BitmapData = new BitmapData(target.width, target.height);
tBitData.draw(target);
duplicate = new Bitmap(tBitData);
return duplicate;
}
克隆目标显示对象(MovieClip 或 Sprite)并返回位图对象。
它可以从目标对象获取位图,但似乎无法获取图像的所有区域。
通过给出目标对象的宽度和高度,但是设计中的目标对象是通过发光效果应用的,所以我的问题是我们可以从显示对象中获取位图数据的所有视图吗?
I have this function:
public static function cloneDpObj(target:DisplayObject):Bitmap
{
var duplicate:Bitmap;
var tBitData:BitmapData = new BitmapData(target.width, target.height);
tBitData.draw(target);
duplicate = new Bitmap(tBitData);
return duplicate;
}
to clone target displayObject (MovieClip or Sprite) and return Bitmap Object.
It can get bitmap from the target object, but it seem don't get all the area of the image.
By give the width and height of target object, but the target object in design was applied by Glow Effect, so my question can we get the all view of bitmapdata from a displayobject?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
BitmapData.draw()
拍摄给定对象的快照,删除舞台上应用的所有转换和滤镜。生成的图像显示了电影库中存在的对象。使用变换和/或过滤器绘制显示对象时有两个基本选项。
BitmapData.draw()
的矩阵参数应用所有转换。绘制后,您可以使用 BitmapData.applyFilter() 将滤镜应用到生成的位图。我通常选择后者。这非常简单。有一些缺点:如果您选择第二种方法,您的目标必须有一个显示列表父级,并且您可能会绘制驻留在父级容器中的不需要的内容。 (但是,这些缺点很容易消除。)
BitmapData.draw()
takes a snapshot of a given object removing all transformations and filters applied on the stage. Resulting image shows object as it is present in your movie library.There are two basic options when drawing display objects with transformations and/or filters.
BitmapData.draw()
. After drawing you can apply filters to resulting bitmap withBitmapData.applyFilter()
.I usually choose the latter. That's pretty straightforward. There are some disadvantages: if you choose the second method, your target has to have a display list parent and you may draw unwanted content that resides in parent container. (However, these drawbacks are easily eliminated.)
您需要计算 DisplayObject 的面积/矩形,包括应用的过滤器占用的面积。幸运的是,您可以通过使用 BitmapData 类的generateFilterRect() 方法。
此外,由于其他原因,如果您需要将 DisplayObject 的转换应用于 BitmapData 快照,您可以传递源 DisplayObject 的 .transform。concatenatedMatrix 作为BitmapData的draw()方法的第二个参数。
You need compute the area/rectangle of your DisplayObject including the area taken by the filter applied. Luckily you can do that with with built-in functionality by using the generateFilterRect() method of the BitmapData class.
Also, for other reasons, if you need the transformation of your DisplayObject applied to the BitmapData snapshot, you can pass the source DisplayObject's .transform.concatenatedMatrix as the second parameter of BitmapData's draw() method.
非常感谢大家抽出宝贵的时间回答我的问题。我改进了该功能,但我更好了,但我注意到捕获结果的宽度是 1 像素偏移,所以我决定将 1 像素添加到位图数据的宽度,我知道这不是一个好的做法。因为我现在必须这样做,所以我还不知道这个问题。这是我们现在的功能:
Thank you very much to all of you that take valuable time answer my question. I improved that function, but I is better, but I notice that the width of result of capture is 1pixel offset, so I decided to add 1 pixel to width of the bitmapdata, I know that is not a good practice. because I have to do that now, I don't know the issue yet. Here is how our function now:
我实际上会选择 Nox 的第一个选项作为更简单的方法,并且修改你的函数来做到这一点只需要额外的一行代码:
I would actually go with Nox's first option as the easier approach, and modifying your function to do it should only take one extra line of code: