我正在使用SDK 1.6.2进行开发。使用存储在Titanium.Filesystem.applicationDataDirectory中的图像的ImageView显示占位符,而不是图像
我的应用程序使用相机捕获并保存图像到Titanium.Filesystem.applicationDataDirectory。
应用程序的一个水龙头应该显示所有存储的图像(细节[路径]存储在数据库中)平铺在屏幕上。
保存图像:
var image = event.media // from camera success
var filename = new Date().getTime() + "-ea.jpg";
bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);
bgImage.write(image);
存储到数据库:
var db = Titanium.Database.open('photoDB');
try{
db.execute('INSERT INTO stored (image) VALUES (?)', bgImage.nativePath);
} catch(e) {
alert(e.message);
}
db.close();
显示的图片:
imageArray = [];
images = [];
var db = Titanium.Database.open('photoDB');
var dbrows = db.execute('select id, date, image from stored order by date asc');
while (dbrows.isValidRow()) {
imageArray.push({
image:dbrows.fieldByName('image')
});
dbrows.next();
}
dbrows.close();
// loop thru and display images
for (var i = 0; i < imageArray.length; i++){
var pushleft = (i % 4) * 75; // tile from left
var pushtop = Math.floor(i/4) * 96; // determine how far from top
var file = Titanium.Filesystem.getFile(imageArray[i].image);
images[i] = Ti.UI.createImageView({
image: imageArray[i].image, // path to image at applicationDataDirectory
width: 75,
height: 96,
left: pushleft + 5, // logic for positioning
top: pushtop + 5, // logic for positioning
store_id: imageArray[i].id
});
win.add(images[i]);
}
不幸的是,虽然瓷砖工作的图像只是显示图像占位符,而不是存储的图像。
我有phonedisk,所以在为我的设备构建应用程序后,我可以查看应用程序目录并且正在存储图像。
我错过了什么?
感谢您将自己的答案。两年后至少有一个人看着这个! – 2013-07-11 17:13:11
哈哈,托尼没问题!很高兴帮助。 – joseym 2013-07-23 12:52:43