diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/ExtensionMethods/ImageMonikerExtensions.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/ExtensionMethods/ImageMonikerExtensions.cs
index 3f62223..34eff3a 100644
--- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/ExtensionMethods/ImageMonikerExtensions.cs
+++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/ExtensionMethods/ImageMonikerExtensions.cs
@@ -34,15 +34,37 @@ public static class ImageMonikerExtensions
return data as BitmapSource;
}
+ ///
+ /// Converts an ImageMoniker to a bitmap in the specified size.
+ ///
+ public static async Task ToBitmapSourceAsync(this ImageMoniker moniker, int size, Color backgroundColor)
+ {
+ await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+
+ IVsUIObject? result = await ToUiObjectAsync(moniker, size, backgroundColor);
+ ErrorHandler.ThrowOnFailure(result.get_Data(out object data));
+
+ return data as BitmapSource;
+ }
+
///
/// Converts an ImageMoniker to an IVsUIObject in the specified size.
///
public static async Task ToUiObjectAsync(this ImageMoniker moniker, int size)
+ {
+ Color backColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
+
+ return await ToUiObjectAsync(moniker, size, backColor);
+ }
+
+ ///
+ /// Converts an ImageMoniker to an IVsUIObject in the specified size with the specified background color.
+ ///
+ public static async Task ToUiObjectAsync(this ImageMoniker moniker, int size, Color backgroundColor)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
IVsImageService2 imageService = await VS.GetRequiredServiceAsync();
- Color backColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
ImageAttributes imageAttributes = new()
{
@@ -52,7 +74,7 @@ public static async Task ToUiObjectAsync(this ImageMoniker moniker,
Dpi = 96,
LogicalHeight = size,
LogicalWidth = size,
- Background = (uint)backColor.ToArgb(),
+ Background = (uint)backgroundColor.ToArgb(),
StructSize = Marshal.SizeOf(typeof(ImageAttributes))
};