从数据库加载图像缓慢

发布于 2024-11-03 03:15:26 字数 1497 浏览 2 评论 0原文

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

有什么想法吗?谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆凄凉。 2024-11-10 03:15:26

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

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

另外,你用的是什么设备? iOS还是安卓?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文