从Flash影片传送位图的Javascript位图、影片、Flash、Javascript

2023-09-08 15:13:03 作者:时间的流逝

我想知道什么是最有效的方式从ActionScript传递的BitmapData 对象为Javascript,所以图像可以在网页上显示出来。

I would like to know what is the most efficient way to transfer BitmapData object from Actionscript to Javascript, so an image can be displayed on webpage.

到目前为止,我已经成功地工艺包含使用数据URI方案Flash中的图像数据的字符串,然后我用 ExternalInterface.call(<函数名>中转移到了Javascript中,数据)

So far, I've managed to craft a string containing image data using data URI scheme in Flash and then I transfered it to the Javascript using ExternalInterface.call("<function_name>", data).

虽然它工作正常,似乎浪费图像转换为文本的再presentation只是转移了。有没有达到同样的清洁/更有效的方法?

While it is working fine, it seems wasteful to convert image to its textual representation just to transfer it. Is there a cleaner/more efficient way to achieve the same?

推荐答案

AS3:

的base64 EN code的BitmapData对象。 例如 然后:

base64 encode your BitmapData object. example then:

ExternalInterface.call("setImage",encodedImg);

JavaScript的:

Javascript:

function setImage(baseSixtyFourEncodedImage)
{
    document.getElementById("myImage").src = "data:" + baseSixtyFourEncodedImage;
}

HTML:

HTML:

<img id="myImage" src="no_image_from_flash_yet.png">

不要忘了导入ExternalInterface的闪光灯到底! 让我知道如何去。

Don't forget to import ExternalInterface on the flash end! let me know how it goes.