Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yannduran/2e5e9b6de06cbfce9010bcf25e2c620c to your computer and use it in GitHub Desktop.
Save yannduran/2e5e9b6de06cbfce9010bcf25e2c620c to your computer and use it in GitHub Desktop.
Uses the IVsImageService2 to convert a KnownMoniker to BitmapSource
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