如何将使用Wpf应用程序中的网络摄像头捕获的图像保存到sqlite数据库
这是我保存的代码。
public static void SaveImageCapture(BitmapSource bitmap)
{
try
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
encoder.QualityLevel = 100;
MemoryStream mm = new MemoryStream();
encoder.Save(mm);
byte[] img = mm.GetBuffer();
DataTable dt = new DataTable();
SQLiteConnection con = new SQLiteConnection(@"data source=F:\Mayur\Vistrack\SqliteDatabases\Vistrack");
con.Open();
SQLiteCommand cmd = new SQLiteCommand("insert into img values('" + img + "')", con);
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
}
}
和加载图片:
BitmapImage bmp = new BitmapImage();
DataTable dt = new DataTable();
SQLiteConnection con = new SQLiteConnection(@"data source=F:\Mayur\Vistrack\SqliteDatabases\Vistrack");
con.Open();
SQLiteCommand cmd = new SQLiteCommand("select * from img", con);
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
da.Fill(dt);
//cmd.ExecuteNonQuery();
con.Close();
byte[] b = (byte[])dt.Rows[0][0];
MemoryStream byteStream = new MemoryStream(b);
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = byteStream;
image.EndInit();
imgCapture.Source = image;
将图像分配给我的图像控制imgCapture它显示:没有找到适合完成此操作的成像组件。