I have spent considerable time trying to retrieve images from SQLite but i have failed miserably. If some one could help me with what i am doing wrong here, that would be greatly appreciated. Below is the code i am using to retrieve a BLOB image stored in SQLite.
SQLiteConnection con = new SQLiteConnection(Properties.Settings.Default.conString);
con.Open();
SQLiteCommand cmd = new SQLiteCommand("SELECT ImageFiles FROM basicconcepts WHERE id=1",con);
SQLiteDataReader reader=cmd.ExecuteReader();
byte[] imageBytes=null;
while (reader.Read())
{
imageBytes = (System.Byte[])reader["ImageFiles"];
}
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
ms.Write(imageBytes, 0, imageBytes.Length);
pictureBox1.Image = Image.FromStream(ms, true);
Here is the Stack Trace of the error that i am getting
System.ArgumentException was caught
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)
at WindowsFormsApplication1.frmMain.getPDF(String c_Name, Int32 pgNo) in C:\Users\Tanmay\Documents\My Projects\E-Excust\E-Excust\E-Excust\frmMain.cs:line 148
InnerException:
PS the above code is inside the getPDF method.
EDIT
I have found a solution for my problem. The problem was, quite surprisingly the sql admin tool i was using. i would strongly recommend not to use sqlite administrator for retrieving BLOB images. I started using SQLite Expert and everything started working fine. Could not believe i racked my head over this for one whole day Thanks everyone for their help, specially the guys who havent answered here but helped me a lot on chat. big thanks to usernane, yas4891, SomeGuy and a few others