从Bitmap获取ImageSource?
我想为我的表单/窗口设置一个像这样的人的背景图像,但是在磁盘上没有图像文件,我在内存中有一个System.Drawing.Bitmap
。
我需要做这样的事情:
this.Background = new ImageBrush(new BitmapImage(bmp));
除了BitmapImage
不会占用Bitmap
, ImageBrush
和我也不确定是否会有其他人。 有一个名为BitmapCacheBrush
但我不知道它是做什么的。
没关系,我明白了。
public static Brush CreateBrushFromBitmap(Bitmap bmp) { return new ImageBrush(Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions())); }
信用