我正在将一些图像下载到我的应用程序中,这样就可以在不消耗任何带宽的情况下显示它们。我用来在我的Android设备上存储图像的代码如下:
var file:File = File.applicationDirectory.resolvePath(fileName);
if (file.exists)
{
file.deleteFile(); //delete it if exists
}
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(data, 0, data.length);
fileStream.close();
var showLocalPath:String = file.nativePath;
要显示图像,我使用以下两个示例:
<s:BitmapImage id="iconStateImage" source="{appContext.CurrentState.IconImage}"/>
<s:Image id="backgroundStateImage" left="0" right="0" top="0" bottom="0" source="{File.applicationDirectory.resolvePath(appContext.CurrentState.BackgroundImage)}"/>
appContext.CurrentState.IconImage
和appContext.CurrentState.BackgroundImage
都与前者fileName
具有相同的路径。即使我试图用完整路径(第二种情况)或短路径(第一种情况)加载图像,我也无法显示它。
我已经在项目上设置了WRITTING权限。
有人可以帮我吗?提前谢谢。
此致
圣塞瓦斯蒂安
答案 0 :(得分:1)
File.applicationDirectory
是只读的;你会想要使用File.applicationStorageDirectory
。
另请参阅How can you delete a file in the application directory?和Flex File documentation。
然后在图像路径前添加“app-storage:/”:
<s:Image id="backgroundStateImage" source="app-storage:/{appContext.CurrentState.BackgroundImage}"/>