0

I wrote a program that works just fine when run from within Visual Studio 2012. However, when I compile and run a release version, I get the following:

System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
   at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
   at System.Drawing.Image.Save(String filename, ImageFormat format)
   at EinsteinRiddle.frmMain.buildImage(Int32& fRow, Int32& rNum, String& strCmd, Int32& itms) in C:\Users\Gerry\Documents\Visual Studio 2012\Projects\Learning and Testing\EinsteinRiddle\EinsteinRiddle\frmMain.vb:line 848
   at EinsteinRiddle.frmMain.btSolve_Click(Object sender, EventArgs e) in C:\Users\Gerry\Documents\Visual Studio 2012\Projects\Learning and Testing\EinsteinRiddle\EinsteinRiddle\frmMain.vb:line 281

The line referenced, frmMain.vb: line 848 is the following:

[line 847] Dim fName As String = <stuff> + ".jpg"
[line 848] bmp.Save(fName, ImageFormat.Jpeg)

Note that the above is inside a Using bmp As New Bitmap(imgHorSize, imgVerSize).

I have no idea why this is happening. Can you help?

GSerg
  • 76,472
  • 17
  • 159
  • 346
GRoston
  • 325
  • 1
  • 3
  • 12
  • Does this answer your question? [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) – GSerg Jul 06 '21 at 20:17
  • Does this answer your question? [A Generic error occurred in GDI+ in Bitmap.Save method](https://stackoverflow.com/q/15862810/11683) – GSerg Jul 06 '21 at 20:18
  • Add to the question the value of `fName`, of `imgHorSize` and `imgVerSize` when the exception is generated and the complete code that includes the `using` block, what calls it and how / when (e.g., there's a secondary Thread involved or anything else meaningful). – Jimi Jul 06 '21 at 23:40
  • How EXACTLY did you create the `Image` object in the first place? That will affect whether it's possible to `Save` it that way. – jmcilhinney Jul 07 '21 at 01:54
  • Usually points to a memory or other resource limit being reached. Double check that pretty much anything else you may be using from System.Drawing namespace is getting disposed. – Ryan Roos Jul 07 '21 at 14:32

0 Answers0