在 Flash 中拍摄显示对象可见区域的快照
我在 flash (AS3) 中有相机输入应用程序,我在它上面画了一些图形。我想拍摄舞台可见区域的图像快照,但只有视频和我在视频上绘制的图形。我想从图像快照中排除控件。我的显示对象布局具有以下关系:
-stage
--canvas (Sprite)
---video (Video)
---overlayed graphics (Sprites, MCs, Shapes)
--controls (Buttons)
舞台大小是固定的,我想拍摄画布元素子级的所有内容的图像快照(相机输入视频和覆盖图形,但不包括控件)。当叠加的图形位于舞台大小的范围内时,我可以制作此图像快照。我是这样做的:
var bmpd:BitmapData = new BitmapData(canvas.width, canvas.height);
bmpd.draw(canvas, new Matrix(1, 0, 0, 1, canvas.x, canvas.y));
但是,当我在画布上的视频顶部绘制的图形超出舞台显示区域的边界时,这会给我带来不想要的结果。如何将图像快照限制在舞台内可见区域的范围内?
谢谢
I have camera input app in flash (AS3) and I draw some graphics over it. I want to take the image snapshot of the stage visible area but only the video an graphics I draw over video. I want to exclude controls from the image snapshot. My display object layout is in following relation:
-stage
--canvas (Sprite)
---video (Video)
---overlayed graphics (Sprites, MCs, Shapes)
--controls (Buttons)
Stage size is fixed and I want to take a image snapshot of everything that is child of my canvas element (camera input video and overlayed graphics, but excluding controls). I am able to make this image snapshot when overlayed graphics are inside the bounds of stage size. I do it like this:
var bmpd:BitmapData = new BitmapData(canvas.width, canvas.height);
bmpd.draw(canvas, new Matrix(1, 0, 0, 1, canvas.x, canvas.y));
But this gives me unwanted result when graphics which I draw on top of video on canvas exceed the bounds of stage display area. How do I limit the image snapshot only in the bounds of visible area inside stage?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我过去所做的是使用 as3corelib,其中包含 JPG 的编码器类(JPGEncoder.as) 和 PNG (PNGEncoder.as)图像文件。这些类使得从显示对象创建图像文件变得非常轻松。
这是我的一个程序中的代码,它使用 FileReference 将整个舞台及其所有子级的 .png 保存到本地磁盘。
在您的情况下,由于您想要除控件之外的所有图层,因此您可以简单地在绘制 biamapData 时使控件图层不可见,然后让它们重新出现。然后使用 PNGEncoder(或 JPGEncoder)对 bitmapData 进行编码,将其分配给 ByteArray 并将 byteArray 保存为 .png(或 .jpg)
what i've done in the past is use the as3corelib, which contains encoder classes for both JPG (JPGEncoder.as) and PNG (PNGEncoder.as) image files. these classes makes it quite effortless to create image files from your display objects.
here's the code from one of my programs which saves a .png of my entire stage and all of it's children to the local disk using FileReference.
in your case, since you want all of your layers except for the controls, you could simply make the controls layer invisible while drawing the biamapData and make them reappear afterwards. then encode your bitmapData using PNGEncoder (or JPGEncoder), assign it to a ByteArray and save the byteArray as an .png (or .jpg)
draw(source:IBitmapDrawable、matrix:Matrix = null、colorTransform:flash.geom:ColorTransform = null、blendMode:String = null、clipRect:Rectangle = null、smoothing:Boolean = false) :void
根据画布大小设置clipRect参数(设置宽度和高度等于画布的宽度和高度)。
draw(source:IBitmapDrawable, matrix:Matrix = null, colorTransform:flash.geom:ColorTransform = null, blendMode:String = null, clipRect:Rectangle = null, smoothing:Boolean = false):void
Set clipRect parameter according to canvas size(set width and height equal your canvas width and height).
bitmapData.copyPixels() 允许您获取 bmpd 中像素的子矩形。
这是两个步骤,我确信在绘制中的clipRectangle 一步就能完成,但我昨天就遇到了这个问题,并且无法让clipRectangle 正常工作,所以我只是采取了这种做法。
bitmapData.copyPixels() would allow you to get a subrectangle of the pixels in bmpd.
That's two steps to do what I am sure clipRectangle in draw would do in one step, but I had exactly this problem yesterday and couldn't get clipRectangle to function properly so I just resorted to doing this instead.