Flex 支持 data uri 方案吗?

发布于 2024-07-11 14:37:04 字数 1851 浏览 5 评论 0原文

我希望在 XML 响应中将许多小的 PNG 文件作为 base64 编码的 URI 传递,但似乎没有办法让 Flex 呈现这些图像。 我正在考虑 data uri 方案,但似乎不支持。

建议的解决方案

  1. 使用 Loader.LoadBytes

尝试过,它似乎不起作用(没有触发任何事件)。

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1276" height="849" creationComplete="drawImage()">
    <mx:Script>
        <![CDATA[
                import mx.controls.Alert;
                import mx.utils.Base64Decoder;

                private function loaderCompleteHandler(event:Event):void {
                        Alert.show("loader done");
            }

            private function errorHandler(e:IOErrorEvent):void {
                Alert.show("error" + e.toString());
            }

                public function drawImage() : void
                {
                        var b64png : String = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==";
                        var l : Loader = new Loader();

                        var decoder : Base64Decoder = new Base64Decoder();
                        decoder.decode(b64png);
                        var bytes : ByteArray = decoder.flush();


                        l.addEventListener(Event.COMPLETE, loaderCompleteHandler);
                        l.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

                        l.loadBytes(bytes);

                }
        ]]>
    </mx:Script>
    <mx:Image x="10" y="10" width="155" height="118" id="image1"/>
</mx:Application>

有人可以告诉我我做错了什么吗?

I wish to pass many small PNG files as base64 encoded URIs within an XML response, but there seems to be no way to make flex present these images. I was thinking of the data uri scheme, but it appears not to be supported.

Proposed solutions

  1. Use Loader.LoadBytes

Tried it and it doesn't seem to work (none of the events are triggered).

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1276" height="849" creationComplete="drawImage()">
    <mx:Script>
        <![CDATA[
                import mx.controls.Alert;
                import mx.utils.Base64Decoder;

                private function loaderCompleteHandler(event:Event):void {
                        Alert.show("loader done");
            }

            private function errorHandler(e:IOErrorEvent):void {
                Alert.show("error" + e.toString());
            }

                public function drawImage() : void
                {
                        var b64png : String = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==";
                        var l : Loader = new Loader();

                        var decoder : Base64Decoder = new Base64Decoder();
                        decoder.decode(b64png);
                        var bytes : ByteArray = decoder.flush();


                        l.addEventListener(Event.COMPLETE, loaderCompleteHandler);
                        l.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

                        l.loadBytes(bytes);

                }
        ]]>
    </mx:Script>
    <mx:Image x="10" y="10" width="155" height="118" id="image1"/>
</mx:Application>

Can someone please tell me what I did wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初雪 2024-07-18 14:37:04

如果将图像数据解码为 ByteArray,则可以使用 Loader.loadBytes(byteArray) 将其加载为图像。

If you decode the image data into a ByteArray then you can use Loader.loadBytes(byteArray) to load it as an image.

呢古 2024-07-18 14:37:04

您可以使用以下内容来加载图像:

var deco64:Base64Decoder = new Base64Decoder;

deco64.decode("base64StringWithTheImageData");

var arrBytes:ByteArray = deco64.toByteArray();

img.load(arrBytes);

希望这有帮助!

You could use something this to load the image:

var deco64:Base64Decoder = new Base64Decoder;

deco64.decode("base64StringWithTheImageData");

var arrBytes:ByteArray = deco64.toByteArray();

img.load(arrBytes);

Hope this helps!

彩扇题诗 2024-07-18 14:37:04

您可以将从解码器返回的字节数组直接分配给图像的源属性。

    <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()">
    <mx:Script>
        <![CDATA[
            import mx.utils.Base64Decoder;

            private function init():void {
                var b64png : String = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==";
                var decoder : Base64Decoder = new Base64Decoder();
                decoder.decode(b64png);
                var bytes : ByteArray = decoder.flush();
                img.source = bytes;
            }
        ]]>
    </mx:Script>
    <mx:Image id="img" />
</mx:Application>

You can assign the byte array returned from the decoder directly to the image's source property.

    <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()">
    <mx:Script>
        <![CDATA[
            import mx.utils.Base64Decoder;

            private function init():void {
                var b64png : String = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==";
                var decoder : Base64Decoder = new Base64Decoder();
                decoder.decode(b64png);
                var bytes : ByteArray = decoder.flush();
                img.source = bytes;
            }
        ]]>
    </mx:Script>
    <mx:Image id="img" />
</mx:Application>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文