i use for a project a function that i found on StackOverflow : https://stackoverflow.com/a/6484754/9535211
The goal of this function is to convert a System.Windows.Media.Imaging.BitmapImage to a System.Drawing.Bitmap.
public Bitmap BitmapImage2Bitmap(BitmapImage bitmapImage)
{
using (MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitmapImage));
enc.Save(outStream);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);
return (new Bitmap(bitmap));
}
}
It works pretty well (even if its realy heavy), but it throw an exception everytime its called :
Exception thrown: 'System.NotSupportedException' in PresentationCore.dll
It seems that it comes from the line :
enc.Save(outStream);
Is there a way to make it disappear ?
Thanks for your help !