从数据库加载图像缓慢
问候。 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的第一个建议是,如果您只显示尺寸为 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?