There is a sqlite database, it has a photo column. I need to take a picture from the base and save it to my computer (to the folder). There is the following code:
private void getImage(string file) { string query = "SELECT photo FROM Tasks WHERE id=" + list_comments[i]; SQLiteCommand cmd = new SQLiteCommand(query, db); try { IDataReader rdr = cmd.ExecuteReader(); try { while (rdr.Read()) { byte[] a = (System.Byte[])rdr[0]; ByteToImage(a, file); } } catch (Exception exc) { /*MessageBox.Show(exc.Message);*/ } } catch (Exception ex) { /*MessageBox.Show(ex.Message);*/ } } public void ByteToImage(byte[] imageBytes, string fileName) { // Convert byte[] to Image MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); ms.Write(imageBytes, 0, imageBytes.Length); System.Drawing.Image image = new Bitmap(ms); //pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); } But it does not work. How to implement correctly?