使用存储在 Titanium.Filesystem.applicationDataDirectory 中的图像的 ImageView 显示占位符,而不是图像
我正在使用 SDK 1.6.2 进行开发。
我的应用程序使用相机捕获图像并将其保存到 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,因此在为我的设备构建应用程序后,我可以查看应用程序目录和正在存储的图像。
我缺少什么?
I'm developing with SDK 1.6.2.
My app uses the camera to capture and save an image to Titanium.Filesystem.applicationDataDirectory.
A tap of the app is supposed to display all stored images (details [path] stored in database) tiled across the screen.
Saving the image:
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);
Storing to database:
var db = Titanium.Database.open('photoDB');
try{
db.execute('INSERT INTO stored (image) VALUES (?)', bgImage.nativePath);
} catch(e) {
alert(e.message);
}
db.close();
Showing the Images:
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]);
}
Unfortunately, while the tiles work the images are just showing the image placeholder, not the stored image.
I have phonedisk, so after building the app for my device I can view the application directory and the images are being stored.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
搞清楚了,谢谢大家的帮助;) <讽刺(才一天,我没有怨恨)
如果其他人有类似的问题,这就是错误所在。
当我将图像位置存储在数据库中时,我存储了完整路径
bgImage.nativePath
。但是,当我更新并重建应用程序时,应用程序 applicationDataDirectory 发生了更改,因此存储的路径无效。所以现在我只是将 var filename 存储在数据库中,当我像这样显示它时:
现在,即使有更新,它也始终指向正确的 applicationDataDirectory
Figured it out, thanks everyone for the help ;) < sarcasm (It's only been a day, I hold no grudges)
Here's what was wrong in case anybody else has a similar issue.
When I was storing the image location in the database I was storing the full path
bgImage.nativePath
. However, when I updated and rebuild the app the apps applicationDataDirectory changed, so the stored path was invalid.So now I just store
var filename
in the database and when I display it like this:Now, even with updates, it always points to the proper applicationDataDirectory