2
    Image img = picturebox_company_logo.Image as Image;
    using (MemoryStream ms = new MemoryStream())
    {
       img.Save(ms, ImageFormat.jpeg);
       byte[] bytes = ms.ToArray();
       cmd.Parameters.Add("@compLogo", SqlDbType.Image).Value = bytes;
    }

i am using C# and sqlserver... and am trying to get image from picturebox and store in into database... database column datatype is 'image'...

when i debug the code it gives exception on img.Save(ms, ImageFormat.jpeg); and the exception message is A generic error occurred in GDI+.

i had tried every possible way but it didn't work out...

i tried to add user permission and other solutions also

Yash
  • 181
  • 1
  • 1
  • 13
  • Possible duplicate of [A Generic error occurred in GDI+ in Bitmap.Save method](https://stackoverflow.com/questions/15862810/a-generic-error-occurred-in-gdi-in-bitmap-save-method) – Lennart Sep 19 '17 at 13:52
  • 1
    unlikely, none of the duplicate's answers seem to address this and OP is taking an approach of in-memory streaming, so the explanations "save over existing file while locked" and "permission issue" would not apply. – Cee McSharpface Sep 19 '17 at 13:55
  • @Yash, `ImageFormat.jpeg` does not exist in my version of C#, are you sure? It should be `ImageFormat.Jpeg` with a capital J. Try `ImageFormat.Png` instead, if that works we can blame it on the jpeg encoder and focus on that. – Cee McSharpface Sep 19 '17 at 13:56
  • Possible duplicate of [A generic error occurred in GDI+, JPEG Image to MemoryStream](https://stackoverflow.com/questions/1053052/a-generic-error-occurred-in-gdi-jpeg-image-to-memorystream) – Cee McSharpface Sep 19 '17 at 13:59
  • i tried JPEG,GIF,PNG and BMP every time i gets same error... – Yash Sep 19 '17 at 14:17
  • strange. did you also try different pictures, to rule out a corrupted pic, and different sizes? – Cee McSharpface Sep 20 '17 at 21:58
  • How is `picturebox_company_logo.Image` loaded? – Nyerguds Mar 11 '18 at 23:53

0 Answers0