如何将使用Wpf应用程序中的网络摄像头捕获的图像保存到sqlite数据库。 [英] How to save image captured using webcam in Wpf application to sqlite database.

查看:82
本文介绍了如何将使用Wpf应用程序中的网络摄像头捕获的图像保存到sqlite数据库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是wpf和sqlite的新手。请指导解决这个问题。如何将使用Wpf应用程序中的网络摄像头捕获的图像保存到sqlite数据库。

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.

推荐答案

您需要在此特定场景中使用BLOB:



存储:

You need to use BLOB for this particular scenario :

TO store :
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

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


这篇关于如何将使用Wpf应用程序中的网络摄像头捕获的图像保存到sqlite数据库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆