从 System.Drawing.Bitmap 加载 WPF BitmapImage [英] Load a WPF BitmapImage from a System.Drawing.Bitmap

查看:31
本文介绍了从 System.Drawing.Bitmap 加载 WPF BitmapImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 System.Drawing.Bitmap 的实例,并希望以 System.Windows.Media.Imaging.BitmapImage<的形式将它提供给我的 WPF 应用程序/代码>.

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.

最好的方法是什么?

推荐答案

感谢 Hallgrim,这是我最终得到的代码:

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

这篇关于从 System.Drawing.Bitmap 加载 WPF BitmapImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆