我正在尝试将一个
我有以下方法将其转换为
有人知道怎么做吗?
代码:
Bitmap(SystemIcons.Question)
转换为BitmapImage
,以便在WPF Image控件中使用它。我有以下方法将其转换为
BitmapSource
,但它返回一个InteropBitmapImage
,现在的问题是如何将它转换为BitmapImage
。直接强制转换似乎不起作用。有人知道怎么做吗?
代码:
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();
}
}