Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ImageView使用存储在Titanium.Filesystem.applicationDataDirectory中的图像显示占位符,而不是图像_Javascript_Imageview_Appcelerator_Placeholder - Fatal编程技术网

Javascript ImageView使用存储在Titanium.Filesystem.applicationDataDirectory中的图像显示占位符,而不是图像

Javascript ImageView使用存储在Titanium.Filesystem.applicationDataDirectory中的图像显示占位符,而不是图像,javascript,imageview,appcelerator,placeholder,Javascript,Imageview,Appcelerator,Placeholder,我正在使用SDK 1.6.2进行开发 我的应用程序使用摄像头捕获图像并将其保存到Titanium.Filesystem.applicationDataDirectory 点击应用程序可以显示整个屏幕上平铺的所有存储图像(存储在数据库中的详细信息[路径]) 保存图像: var image = event.media // from camera success var filename = new Date().getTime() + "-ea.jpg"; bgImage = Titanium

我正在使用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]);
}
存储到数据库:

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]);
}
显示图像:

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]);
}
imageArray=[];
图像=[];
var db=tianium.Database.open('photoDB');
var dbrows=db.execute('select id,date,image from storageorder by date asc');
while(dbrows.isValidRow()){
imageArray.push({
image:dbrows.fieldByName('image'))
}); 
dbrows.next();
}
dbrows.close();
//循环通过并显示图像
对于(var i=0;i
不幸的是,当平铺工作时,图像只是显示图像占位符,而不是存储的图像

我有phonedisk,因此在为我的设备构建应用程序后,我可以查看应用程序目录和存储的图像


我错过了什么?

找到了答案,谢谢大家的帮助;)讽刺(才过了一天,我没有怨恨)

如果其他人也有类似的问题,这里是错误的地方

// Create a file name
var filename = new Date().getTime() + "-ea.jpg";

// Create the file in the application directory
bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);

// Write the image to the new file (image created from camera)
bgImage.write(image);
在数据库中存储图像位置时,我存储的是完整路径
bgImage.nativePath
。但是,当我更新并重建应用程序时,appsapplicationDataDirectory已更改,因此存储的路径无效

所以现在我只需将
var filename
存储在数据库中,当我这样显示它时:

images[i] = Ti.UI.createImageView({
    image: Titanium.Filesystem.applicationDataDirectory + Ti.Filesystem.separator + 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
});

现在,即使有更新,它也总是指向正确的应用程序数据目录

,感谢您添加自己的答案。两年后,至少有一个人看到了这个!