Skip to content

Commit 3fb426b

Browse files
Merge branch 'VsixCommunity:master' into master
2 parents 6798dea + 90379cf commit 3fb426b

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/toolkit/Community.VisualStudio.Toolkit.Shared/ExtensionMethods/ImageMonikerExtensions.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)