-
-
Save yannduran/2e5e9b6de06cbfce9010bcf25e2c620c to your computer and use it in GitHub Desktop.
Uses the IVsImageService2 to convert a KnownMoniker to BitmapSource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static BitmapSource GetImage(ImageMoniker moniker, int size) | |
{ | |
ImageAttributes imageAttributes = new ImageAttributes(); | |
imageAttributes.Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags; | |
imageAttributes.ImageType = (uint)_UIImageType.IT_Bitmap; | |
imageAttributes.Format = (uint)_UIDataFormat.DF_WPF; | |
imageAttributes.LogicalHeight = size; | |
imageAttributes.LogicalWidth = size; | |
imageAttributes.StructSize = Marshal.SizeOf(typeof(ImageAttributes)); | |
var service = (IVsImageService2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsImageService)); | |
IVsUIObject result = service.GetImage(moniker, imageAttributes); | |
object data; | |
result.get_Data(out data); | |
if (data == null) | |
return null; | |
return data as BitmapSource; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment