Click here to Skip to main content
15,886,091 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new to wpf and sqlite. Please guide to solve out this issue. How to save image captured using webcam in Wpf application to sqlite database.
Posted
Comments
Mehdi Gholam 24-Sep-14 1:31am    
How far have you got, and where are you stuck?
Mayur_Pawar 24-Sep-14 1:44am    
I have bitmapSource image but don't know how and in which format i should save it to sqlite database so that again i can fetch and show the same image on image control in wpf

1 solution

You need to use BLOB for this particular scenario :

TO store :
C#
public void insertImg(int id , Bitmap img ) {   


    byte[] data = getBitmapAsByteArray(img); // this is a function

    insertStatement_logo.bindLong(1, id);       
    insertStatement_logo.bindBlob(2, data);

    insertStatement_logo.executeInsert();
    insertStatement_logo.clearBindings() ;

}

 public static byte[] getBitmapAsByteArray(Bitmap bitmap) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 0, outputStream);       
    return outputStream.toByteArray();
}


To retreive
C#
public Bitmap getImage(int i){

    String qu = "select img  from table where feedid=" + i ;
    Cursor cur = db.rawQuery(qu, null);

    if (cur.moveToFirst()){
        byte[] imgByte = cur.getBlob(0);
        cur.close();
        return BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length);
    }
    if (cur != null && !cur.isClosed()) {
        cur.close();
    }       

    return null ;
} 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900