我正在尝试转换Bitmap (SystemIcons.Question)
to a BitmapImage
所以我可以在 WPF Image 控件中使用它。
我有以下方法将其转换为BitmapSource
,但它返回一个InteropBitmapImage
,现在的问题是如何将其转换为BitmapImage
。直接演员似乎不起作用。
有人知道该怎么做吗?
CODE:
public BitmapSource ConvertToBitmapSource()
{
int width = SystemIcons.Question.Width;
int height = SystemIcons.Question.Height;
object a = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(SystemIcons.Question.ToBitmap().GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(width, height));
return (BitmapSource)a;
}
返回 BitmapImage 的属性:(绑定到我的图像控件)
public BitmapImage QuestionIcon
{
get
{
return (BitmapImage)ConvertToBitmapSource();
}
}
InteropBitmapImage
继承自ImageSource
,所以你可以直接在Image
控制。你不需要它成为BitmapImage
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)