Load a WPF BitmapImage from a System.Drawing.Bitmap

前端 未结 10 2038
天涯浪人
天涯浪人 2020-11-22 04:39

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<

10条回答
  •  北海茫月
    2020-11-22 05:35

    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));
    

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

提交回复
热议问题