本文介绍了从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

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

08-01 07:07