【问题标题】:Slow loading of images from database从数据库加载图像缓慢
【发布时间】:2011-04-23 03:33:14
【问题描述】:

您好。 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 秒。如果我不知道等待,我会认为它已损坏并离开应用程序...

有什么想法吗?谢谢!

【问题讨论】:

    标签: performance sqlite filesystems titanium appcelerator


    【解决方案1】:

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

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

    另外,您使用的是什么设备? IOS还是安卓?

    【讨论】:

    • 亚伦,感谢您的回复。我正在保存整个图像,因为稍后将使用整个图像并将其上传到服务器。 iOS
    • 我有同样的情况,但我保存了两个版本的图像。它可能在 wi-fi 上运行良好,但如果要在 3G 上使用该应用程序,您将有一个糟糕的用户体验,通过网络来回传输巨大的图像......恕我直言。
    • 我将尝试创建缩略图,并让您知道它是如何工作的。感谢@Aaron Saunders 的提示,我会尽快报告。
    • 创建单独的缩略图图像成倍地提高了速度。希望避免存储同一图像的多个版本,但如果迫不得已,那比可悲的长时间加载更容易接受。谢谢@Aaron。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    • 1970-01-01
    • 2021-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多