从System.Drawing.Bitmap加载WPF BitmapImage的

问题描述:

我有一个 System.Drawing.Bitmap 的实例,并想将其提供给我的WPF应用程序在系统的形式.Windows.Media.Imaging.BitmapImage

I have an instance of a System.Drawing.Bitmap and would like to make it available to my WPF app in the form of a System.Windows.Media.Imaging.BitmapImage.

什么是最好的办法了吗?

What would be the best approach for this?

由于Hallgrim,这里是code我结束了:

Thanks to Hallgrim, here is the code I ended up with:

ScreenCapture = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
   bmp.GetHbitmap(), 
   IntPtr.Zero, 
   System.Windows.Int32Rect.Empty, 
   BitmapSizeOptions.FromWidthAndHeight(width, height));

我也结束了在我原来的问题绑定到的BitmapSource而不是一个BitmapImage的

I also ended up binding to a BitmapSource instead of a BitmapImage as in my original question