How do I use a saved image path?
K, here's the run down…
- Get image from the photogallery or camera
- When image is selected, I write a temporary file to the filesystem and record the nativePath in an app.property
- On a different view, I'd like to use that image. How do I use a saved image path?
Everytime I do what's below, the app can't find the path. Should I be using 'url', 'path', 'backgroundImage', 'motherfuton', what?
var thumb = Titanium.App.Properties.getString('theImage');
Titanium.API.info('READING IT IN: '+thumb); // this outputs correctly
var thumbView = Titanium.UI.createImageView({
url:thumb
});
view.add(thumbView);
Error info generated by the console:
[ERROR] Failed to load image: (null), Error: Error Domain=ASIHTTPRequestErrorDomain Code=5 UserInfo=0x503f2a0 "Unable to create request (bad url?)"
5 Answers
-
Accepted Answer
Try this:
var thumb = Ti.App.Properties.getString('theImage'); var file = Ti.Filesystem.getFile(thumb); var thumbView = Ti.UI.createImageView({ image:file }); view.add(thumbView);
See, eg,
image_view_file.js
. -
First off, let me just say that I appreciate your time. I appreciate the code snippet and the link. Unfortunately this didn't work for me:
var thumb = Ti.App.Properties.getString('theImage'); var file = Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,thumb); var thumbnailView = Titanium.UI.createImageView({ url:file }); view.add(thumbnailView);
Gives me this:
[ERROR] Failed to load image: (null), Error: Error Domain=ASIHTTPRequestErrorDomain Code=5 UserInfo=0x503b2b0 "Unable to create request (bad url?)"
-
I used the
image
property in my code, not theurl
property - did you try that too?You also don't need to pass
Titanium.Filesystem.resourcesDirectory
as a parameter togetFile
if you're storing the full path. ThegetFile
function just concatenates its parameters. -
Thanks again for checking back. Yes, sir. Sorry about that - I tried the url version last then copied and pasted. I used the image version to no avail.
I saw another version of this example floating around and it used a different Filesystem location, and I tried each, but that didn't work either.
Titanium.Filesystem.resourcesDirectory vs. Titanium.Filesystem.applicationDataDirectoryNot entirely sure what the differences are, but I tried them anyway. Any ideas?
-
I also tried fireEvent to pass the value of the event.media to the imageView, but that didn't work either. I'm kind of at my wits end here. Anybody?