I use the following code for output of my calculations which it should be a PNG picture. I do not understand why in Debug run the last line gives me a System.Runtime.InteropServices.ExternalException. On the Release run everything is OK.
I found on the net that this error may occur when the image is being used by other part of code, but in my case it is not true.
//using System;
//using System.Drawing;
//using System.Drawing.Imaging;
Bitmap png = new Bitmap(this.xPixels, this.yPixels, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(png);
g.Clear(Color.White);
g.DrawString(currentTime, myFont, mySolidBrush, timeX, timeY, myXTitleFormat);
// write image to file
string path4 = string.Concat(Environment.CurrentDirectory, @"\Output\T1\" + this.fileName + ".png");
png.Save(path4, ImageFormat.Png);
The online help says that "The image was saved with the wrong image format".
It's also strange that you do stuff with the
Graphicsobject, but save using theBitmap. Do the operations made withginfluence theBitmap?The following code raises the exception whether in debug or release mode: