0
function PgMain_rptArticles_OnRowRender(e){
    var records = Data.execute('select * from Articles');
    Data.Dataset1.seek(e.rowIndex);

       Pages.PgMain.rptArticles.Image1.image = records.rows[e.rowIndex][3];
       Pages. PgMain.rptArticles.Label1.text = records.rows[e.rowIndex][1];
       Pages. PgMain.rptArticles.Label2.text = records.rows[e.rowIndex][2]       
}

如何从数据库中获取图像?

4

1 回答 1

1

将大型二进制文件直接保存到数据库是非常少见的。一种更常见的方法是将图像保存到文件中并保存到数据库的路径。

看到一些讨论:

如何将图像存储在 SQLite 数据库中

Android 将图像保存到 SQLite 或 SDCard 或内存

将图像保存到 SQLITE 中?

我假设您更愿意保存对数据库的引用,我的回答就是基于此。

看看这里的例子:http: //docs.smartface.io/html/T_SMF_IO_File.htm

SMF.Multimedia.startCamera({
    cameraType : 1, //rear camera
    resolution : 2, //large resolution
    autoFocus : true,
    onStart : function () {}, //do nothing
    onCapture : function (e) {
        var photoFile = new SMF.IO.File(e.photoUri); //the full URI is given
        var destination = SMF.IO.applicationDataDirectory + //predefined path already containing separator at the end
            "data" + SMF.IO.pathSeperator + "tbl1" +
            SMF.IO.pathSeperator + photoFile.name; //name gives file name with extension
        var targetFile =  new SMF.IO.File(destination);
        if(!targetFile.exists) {
            if(photoFile.move(destination)) { //if moved successfully
                //photoFile nativePath has been updated
                Data.execute("Insert into tbl1 (image) values(?)",
                    photoFile.nativePath); //records reference to database
            }
        }
    },
    onCancel : function () {}, //do nothing
    onFailure : function () {}
    //do nothing
});

您将“目标”变量(参考上面的示例)保存到数据库中,然后获取部分将如下所示:

Pages.PgMain.rptArticles.Image1.image = SMF.Image(records.rows[e.rowIndex][3]);
于 2015-02-12T15:02:52.937 回答