flex:从swfloader加载的swf中截取屏幕截图

问题描述:

我可以使用 SWFLoader 类从加载的 swf 中保存屏幕截图吗?

can i save a screenshot from a loaded swf using the SWFLoader class ?

如果加载的 swf 已经在 swfLoader 中处于所需状态,您应该可以这样做

In case the loaded swf is already in a desired state in swfLoader, you should be able to do this

    var bitmapData:BitmapData =
        new BitmapData(swfLoader.content.width, swfLoader.content.height);
    bitmapData.draw(swfLoader);
    var bitmap:Bitmap = new Bitmap(bitmapData);
    var image:Image = new Image;
    image.source = bitmap;
    addChild(image);

这会将生成的屏幕截图添加到您的应用程序的显示列表中.当然,如果你想保存它,你可以把bitmapData 编码成PNG,例如.你可以找到很多这方面的教程.如果您使用的是 AIR,您可以简单地将其保存在用户的磁盘上.如果您的应用在网页上,您可能需要一些服务器端支持来保存图像.

This would add the resulting screen capture in the display list of your application. Of course, if you want to save it, you can take the bitmapData and encode it into PNG, for example. You can find plenty of tutorials for this. If you're using AIR you can simply save it on the user's disk. In case your app is on a web page, you probably need some server-side support for saving the image.