I want to save jpg images in a SqLite database, and I'm using this code for now:
public byte[] ImageToByte(Image image, System.Drawing.Imaging.ImageFormat format) { using (MemoryStream ms = new MemoryStream()) { image.Save(ms, format); byte[] imageBytes = ms.ToArray(); return imageBytes; } } void btn_click()... { photo = new Bitmap("invoker.jpg"); pic = ImageToByte(photo, System.Drawing.Imaging.ImageFormat.Jpeg); SaveImage(pic); }
UPDATE
void SaveImage(byte[] imagen) { string conStringDatosUsuarios = @" Data Source = \bang.sqlite3 ;Version=3"; SQLiteConnection con = new SQLiteConnection(conStringDatosUsuarios); SQLiteCommand cmd = con.CreateCommand(); cmd.CommandText = String.Format("INSERT INTO tbl_pictures (record_id, pic) VALUES ('1', @0);"); SQLiteParameter param = new SQLiteParameter("@0", System.Data.DbType.Binary); param.Value = imagen; cmd.Parameters.Add(param); con.Open(); try { cmd.ExecuteNonQuery(); } catch (Exception exc1) { MessageBox.Show(exc1.Message); } con.Close(); }
source share