How to save image captured using webcam in Wpf application to sqlite database
Here is my code to save .
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)
{
}
}
and for Loading image:
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;
while assignning image to my image controle imgCapture it's showing :No imaging component suitable to complete this operation was found.