How to display the jpg image from applicationData Directory
Here is my code, which does not display:
var f=Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "a.jpg");
var contents = f.read();
var magCover1 = Titanium.UI.createImageView({
url: content,
height:145,
width:114,
bottom:10
});
can anyone help this?
thanks
5 Answers
-
im totally new to titanium but shouldn´t it be
url: contents
?maxi
-
You have to add it to a view.
var win = Ti.UI.currentWindow;
win.add(magCover1);
-
In case anyone is searching for a solution to displaying an image from the Application Data directory from within a webview, or in a Desktop application. Any references to the file need to be prefixed with file:///
http://blog.rapiddg.com/2011/04/reference-application-data-files-when-creating-a-titanium-desktop-application/
-
var f=Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "a.jpg"); var magCover1 = Ti.UI.createImageView({ url: f.nativePath, height:145, width:114, bottom:10 });
The nativePath property works also
-
Try :
var data_dir = Ti.Filesystem.applicationDataDirectory; var image_name = 'a.jpg'; var magCover1 = Ti.UI.createImageView({ image: data_dir+'/'+image_name, height:145, width:114, bottom:10 });