获取存储在 Ti.Filesystem appcelerator 中的图像
Fetch Image stored in Ti.Filesystem appcelerator
我已将图像存储在 Ti.FileSystem(appcelerator)中,并且已成功存储。但是我无法取回它并在 ImageView
中显示
FullFileName="HA_2312751361_0566296329";
var fullFileNameForForm=FullFileName+"_form.png";
var fileForm = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,fullFileNameForForm);
console.log("contents="+fileForm); // It gets the contents of the file
if(fileForm.exists()){
var contents=fileForm.read();
var image=Titanium.Filesystem.applicationDataDirectory + Ti.Filesystem.separator + contents.image;
//it crashes in above line for contents.image
$.id_buttonImage.backgroundImage=image;
}
else{
console.log('fileNotExists');
}
您可以在检查它是否存在后直接使用 $.id_buttonImage.backgroundImage=fileForm.nativePath;
。由于它已经是 link 文件,因此您无需再次创建路径。
我已将图像存储在 Ti.FileSystem(appcelerator)中,并且已成功存储。但是我无法取回它并在 ImageView
中显示FullFileName="HA_2312751361_0566296329";
var fullFileNameForForm=FullFileName+"_form.png";
var fileForm = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,fullFileNameForForm);
console.log("contents="+fileForm); // It gets the contents of the file
if(fileForm.exists()){
var contents=fileForm.read();
var image=Titanium.Filesystem.applicationDataDirectory + Ti.Filesystem.separator + contents.image;
//it crashes in above line for contents.image
$.id_buttonImage.backgroundImage=image;
}
else{
console.log('fileNotExists');
}
您可以在检查它是否存在后直接使用 $.id_buttonImage.backgroundImage=fileForm.nativePath;
。由于它已经是 link 文件,因此您无需再次创建路径。