In http://social.msdn.microsoft.com/Forums/vstudio/en-US/b15357f1-ad9d-4c80-9ec1-92c786cca4e6/bitmapsave-a-generic-error-occurred-in-gdi?forum=netfxbcl, someone suggests a workaround through a memory stream to solve 'generic GDI+ error' exceptions when saving an image to a file.
However, I have this problem when saving to a memory stream in the first place.
This code throws a "Generic GDI error" exception on the 2nd save (Image2.save).
In my actual application, the image (after the first save) makes a detour through a database (varbinary(max) column) and back to a memory buffer and an image before the second save is called, with no difference: the error still occurs.
For backward compatibility to some mighty old machines (stilll running Win2000!) it all has to happen in framework 2.0, but the error occurs on my development machine in 4.0 client profile just as well.
Dim Image1 As Image = Image.FromFile("C:\Users\Public\Pictures\Sample Pictures\Desert.jpg") Dim Buffer1 As Byte() Using MemoryStream1 As New IO.MemoryStream Image1.Save(MemoryStream1, System.Drawing.Imaging.ImageFormat.Jpeg) Buffer1 = MemoryStream1.ToArray End Using Dim Image2 As Image Using MemoryStream2 As New IO.MemoryStream(Buffer1) Image2 = Image.FromStream(MemoryStream2) End Using Dim Buffer3 As Byte() Using MemoryStream3 As New IO.MemoryStream Image2.Save(MemoryStream3, System.Drawing.Imaging.ImageFormat.Jpeg) Buffer3 = MemoryStream3.ToArray End Using