@@ -34,15 +34,37 @@ public static class ImageMonikerExtensions
3434 return data as BitmapSource ;
3535 }
3636
37+ /// <summary>
38+ /// Converts an ImageMoniker to a bitmap in the specified size.
39+ /// </summary>
40+ public static async Task < BitmapSource ? > ToBitmapSourceAsync ( this ImageMoniker moniker , int size , Color backgroundColor )
41+ {
42+ await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
43+
44+ IVsUIObject ? result = await ToUiObjectAsync ( moniker , size , backgroundColor ) ;
45+ ErrorHandler . ThrowOnFailure ( result . get_Data ( out object data ) ) ;
46+
47+ return data as BitmapSource ;
48+ }
49+
3750 /// <summary>
3851 /// Converts an ImageMoniker to an IVsUIObject in the specified size.
3952 /// </summary>
4053 public static async Task < IVsUIObject > ToUiObjectAsync ( this ImageMoniker moniker , int size )
54+ {
55+ Color backColor = VSColorTheme . GetThemedColor ( EnvironmentColors . ToolWindowBackgroundColorKey ) ;
56+
57+ return await ToUiObjectAsync ( moniker , size , backColor ) ;
58+ }
59+
60+ /// <summary>
61+ /// Converts an ImageMoniker to an IVsUIObject in the specified size with the specified background color.
62+ /// </summary>
63+ public static async Task < IVsUIObject > ToUiObjectAsync ( this ImageMoniker moniker , int size , Color backgroundColor )
4164 {
4265 await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
4366
4467 IVsImageService2 imageService = await VS . GetRequiredServiceAsync < SVsImageService , IVsImageService2 > ( ) ;
45- Color backColor = VSColorTheme . GetThemedColor ( EnvironmentColors . ToolWindowBackgroundColorKey ) ;
4668
4769 ImageAttributes imageAttributes = new ( )
4870 {
@@ -52,7 +74,7 @@ public static async Task<IVsUIObject> ToUiObjectAsync(this ImageMoniker moniker,
5274 Dpi = 96 ,
5375 LogicalHeight = size ,
5476 LogicalWidth = size ,
55- Background = ( uint ) backColor . ToArgb ( ) ,
77+ Background = ( uint ) backgroundColor . ToArgb ( ) ,
5678 StructSize = Marshal . SizeOf ( typeof ( ImageAttributes ) )
5779 } ;
5880
0 commit comments