动作:图像的base64字符串可能吗? [英] Actionscript: image to base64 string possible?

查看:159
本文介绍了动作:图像的base64字符串可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能到选定的图像转换成的base64 EN codeD字符串?

Is it possible to convert an selected image into base64 encoded string?

将图像上传好的和简单的解决方案。 :)

Would be nice and easy solution for image uploader. :)

感谢;)

推荐答案

如果你想连接code加载图像的字节数组,你可以从mx.utils使用Base64En codeR类<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/Base64En$c$cr.html">Base64En$c$cr.

If you're wanting to encode the byteArray of a loaded image, you could use the Base64Encoder class from mx.utils Base64Encoder.

是这样的:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.load(new URLRequest("img.jpg"));

function loadComplete(e:Event):void {
    loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
    var bmd:BitmapData = Bitmap(e.target.content).bitmapData;
    var ba:ByteArray = bmd.getPixels(new Rectangle(0,0,bmd.width,bmd.height));
    var b64:Base64Encoder = new Base64Encoder();
    b64.encodeBytes(ba);
    trace(b64.toString());
}

我不得不追查类<一href="http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/framework/src/mx/utils/Base64En$c$cr.as">here.

此外,还有,我发现,但没有这里测试另外的Base64类......但看起来像它的工作原理类似。

Also, there's another Base64 class that I found but haven't tested here...but looks like it works similarly.

希望有所帮助。

这篇关于动作:图像的base64字符串可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆