InteropBitmap zu BitmapImage
Ich versuche eine zu konvertierenBitmap (SystemIcons.Question)
zu einemBitmapImage
also kann ich es in einem WPF-Image-Steuerelement verwenden.
Ich habe die folgende Methode, um es zu konvertierenBitmapSource
, aber es gibt eineInteropBitmapImage
, jetzt ist das Problem, wie man es in ein konvertiertBitmapImage
. Eine direkte Besetzung scheint nicht zu funktionieren.
Weiß jemand, wie es geht?
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;
}
Eigenschaft, um BitmapImage zurückzugeben: (An mein Bildsteuerelement gebunden)
public BitmapImage QuestionIcon
{
get
{
return (BitmapImage)ConvertToBitmapSource();
}
}