从Flash影片传送位图的Javascript [英] Transfer bitmap from Flash movie to Javascript
问题描述
我想知道什么是最有效的方式从ActionScript传递的BitmapData code>对象为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.
这篇关于从Flash影片传送位图的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!