Convert System.Windows.Media.ImageSource to System.Drawing.Bitmap

its older OP, but still it can come handy for some other people, as it took some time to find cleaner solution without dll interop or clipboard hacks.

this worked for me, you can use pngencoder to cut the image size before saving to file or rtf stream

private System.Drawing.Image ImageWpfToGDI(System.Windows.Media.ImageSource image) {
  MemoryStream ms = new MemoryStream();
  var encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
  encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(image as System.Windows.Media.Imaging.BitmapSource));
  encoder.Save(ms);
  ms.Flush();      
  return System.Drawing.Image.FromStream(ms);
}

Leave a Comment