Slow loading of images from database
Greetings. SDK 1.6.2
I am storing the location of camera captures in a database along with some other information.
I have a window that loops thru the database and displays the images in small, tiled thumbnails.
The more images that I have the longer this window takes to load (remains blank until finished)
Here's how I'm calling the images:
var imageArray = [];
var images = [];
// open and parse database
var db = Titanium.Database.open('photoDB');
var dbrows = db.execute('select id, date, image, tags from images order by date asc');
while (dbrows.isValidRow()) {
imagesArray.push({
id: dbrows.fieldByName('id'),
image:dbrows.fieldByName('image'), // image is the location of the stored image inside of applicationDataDirectory
tags:dbrows.fieldByName('tags')
});
dbrows.next();
}
dbrows.close();
db.close();
// Load in the images
for (var i = 0; i < imageArray.length; i++){
var pushleft = ((i % 4) * 76); // tile from left
var pushtop = (Math.floor(i/4) * 100); //tile from top
var file = Titanium.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, imageArray[i].image);
if(file.exists()){
images[i] = Ti.UI.createImageView({
image: file.nativePath,
width: 75,
height: 96,
left: pushleft,
top: pushtop,
开发者_如何学编程 store_id: imageArray[i].id,
zIndex: 99
});
win.add(images[i]);
}
}
I'm not sure if the lag is due getFile
or maybe the size of the images being stored?
I had 10 images stored and this window took 13 seconds to load. If I didn't know to wait I would think it was broken and left the app...
Any thoughts? Thanks!
my first suggestion would be that if you are only show an image with dimensions of 75 X 96; then why save the much larger image?
why dont you save a thumbnail of the image by resizing it first.
Also, what device are you on? IOS or Android?
精彩评论