user4516606
user4516606

Reputation: 153

Get Image From Database

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]       
}

How can i get image from database?

Upvotes: 0

Views: 250

Answers (1)

SerkanSerttop
SerkanSerttop

Reputation: 588

It is very uncommon to save large binary files directly to the database. A more common approach is to save the image to a file and save the path to the database.

See few of the discussions:

How to store image in SQLite database

Android Save images to SQLite or SDCard or memory

saving image into SQLITE?

I'm assuming you would prefer to save a reference to the database, and my answer is based upon this.

Take a look at the example here: 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
});

You would save the "destination" variable (referring to the example above) to the database and the fetching part would then be like this:

Pages.PgMain.rptArticles.Image1.image = SMF.Image(records.rows[e.rowIndex][3]);

Upvotes: 1

Related Questions