ImageView using an image stored in Titanium.Filesystem.applicationDataDirectory displays a placeholder, not an image

I am developing SDK 1.6.2.

My application uses the camera to capture and save images in Titanium.Filesystem.applicationDataDirectory.

The application crane should display all saved images (details [path] stored in the database), alternating across the screen.

Saving image:

var image = event.media // from camera success var filename = new Date().getTime() + "-ea.jpg"; bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename); bgImage.write(image); 

Database storage:

 var db = Titanium.Database.open('photoDB'); try{ db.execute('INSERT INTO stored (image) VALUES (?)', bgImage.nativePath); } catch(e) { alert(e.message); } db.close(); 

Image display:

 imageArray = []; images = []; var db = Titanium.Database.open('photoDB'); var dbrows = db.execute('select id, date, image from stored order by date asc'); while (dbrows.isValidRow()) { imageArray.push({ image:dbrows.fieldByName('image') }); dbrows.next(); } dbrows.close(); // loop thru and display images for (var i = 0; i < imageArray.length; i++){ var pushleft = (i % 4) * 75; // tile from left var pushtop = Math.floor(i/4) * 96; // determine how far from top var file = Titanium.Filesystem.getFile(imageArray[i].image); images[i] = Ti.UI.createImageView({ image: imageArray[i].image, // path to image at applicationDataDirectory width: 75, height: 96, left: pushleft + 5, // logic for positioning top: pushtop + 5, // logic for positioning store_id: imageArray[i].id }); win.add(images[i]); } 

Unfortunately, while the tiles work, the image just displays the image placeholder, not the saved image.

I have phonedisk, so after creating the application for my device, I can browse the application directory and save the images.

What am I missing?

+6
source share
1 answer

I thought, thanks to everyone for the help;) <sarcasm (It was only a day, I do not regret it)

There is something wrong if someone else has a problem.

 // Create a file name var filename = new Date().getTime() + "-ea.jpg"; // Create the file in the application directory bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename); // Write the image to the new file (image created from camera) bgImage.write(image); 

When I stored the location of the image in the database, I stored the full path bgImage.nativePath . However, when I updated and rebuilt the application, applicationDataDirectory applications changed, so the saved path was invalid.

So now I just store var filename in the database and when I display it like this:

 images[i] = Ti.UI.createImageView({ image: Titanium.Filesystem.applicationDataDirectory + Ti.Filesystem.separator + imageArray[i].image, // path to image at applicationDataDirectory width: 75, height: 96, left: pushleft + 5, // logic for positioning top: pushtop + 5, // logic for positioning store_id: imageArray[i].id }); 

Now, even with updates, it always points to the corresponding applicationDataDirectory

+9
source

Source: https://habr.com/ru/post/886316/


All Articles