简体   繁体   中英

Display image with absolute path in Flex Air

I have very simple Flex Air application where I'd like to load image from documents directory:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function init(event:FlexEvent):void {
                image.source = File.documentsDirectory.resolvePath('image.jpg').nativePath;
            }
        ]]>
    </fx:Script>

    <s:BitmapImage id="image"/>

</s:WindowedApplication>

The problem is that Flex Air doesn't know how to handle native (absolute) path.

Looks very easy, but I don't know how to solve it...

您需要一个URL(或ByteArray)来加载非嵌入式图像,因此请使用File的url属性而不是nativePath

image.source = File.documentsDirectory.resolvePath('image.jpg').url;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM