In our application we have a problem with an ExternalException in GDI+. The application is distributed and runs on over 100 computers successfully and we cannot reproduce it in our test environment. However one single computer crashes with the mentioned exception.
The Bitmap
was previously loaded via a resx file and the BitmapImage
is used in a WPF part of the application just for displaying.
Here's the corresponding code:
private static BitmapImage ConvertToImage(Bitmap bitmap)
{
var bitmapImage = new BitmapImage();
using (var memory = new MemoryStream())
{
bitmap.Save(memory, ImageFormat.Png);
memory.Position = 0;
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
}
return bitmapImage;
}
The application crashes when calling
bitmap.Save
The computer has Windows 7 x64 installed with .NET 4.0.
Any hints on what this could be?
EDIT 1:
I didn't find out so far what's causing the exception. We found out that the exception only happens with some specific images. But all images are in the PNG
format.
For now we will stick to the solution of using CreateBitmapSourceFromHBitmap
which is working for us. CreateBitmapSourceFromHBitmap - Stackoverflow post