从数据库缓慢加载图像

时间:2011-04-23 03:33:14

标签: performance sqlite filesystems titanium appcelerator

问候。 SDK 1.6.2

我将摄像头捕获的位置与其他一些信息一起存储在数据库中。

我有一个循环通过数据库的窗口,并以小的平铺缩略图显示图像。

我拥有的图像越多,此窗口加载的时间越长(保持空白直到完成)

以下是我调用图片的方式:

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]);
    }
}

我不确定滞后是由于getFile还是存储图像的大小?

我存储了10张图像,此窗口需要13秒才能加载。如果我不知道要等待,我会认为它被打破并离开应用程序......

有什么想法?谢谢!

1 个答案:

答案 0 :(得分:2)

我的第一个建议是,如果您只显示尺寸为75 X 96的图像;那为什么要保存更大的图像?

为什么不先通过调整大小来保存图像的缩略图。

另外,你在用什么设备? IOS还是Android?

相关问题