I created a WPF project which has a settings window as main window and from there I open a game window. When opening the game window, the following code creates one long image strip out of several images.
var target = new System.Drawing.Bitmap((int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
var graphics = System.Drawing.Graphics.FromImage(target);
graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
int i = 0;
foreach (Image img in images)
{
System.Drawing.Image drawingImg = ConvertWpfImageToImage(img);
System.Drawing.Bitmap source = new System.Drawing.Bitmap(drawingImg);
graphics.DrawImage(source, i, 0);
i += 320;
}
target.Save(@".\resources\images\conveyerBeltSymbols\bigPicture.png");
This seems to be no problem (although I am saving a bitmap image as png, I know that) at the first time but when I close the second window and try to open it again (without closing the first window too) I get External Exception was unhandled. A generic error occurred in GDI+
.
I tried adding Dispose()
to both graphics
and target
and also tried to add ImageFormat.Png
to the target.Save
method but nothing worked for me.
Has anyone got a solution?