public IVsUIObject GetVsUiObject(ImageMoniker imageMoniker, ImageAttributes imageAttributes) { try { ThreadHelper.ThrowIfNotOnUIThread(); var vsUiObject = _vsImageService.GetImage(imageMoniker, imageAttributes); return(vsUiObject); } catch { return(null); } }
public static ImageSource GetIconForImageMoniker(ImageMoniker?imageMoniker, int sizeX, int sizeY) { if (imageMoniker == null) { return(null); } IVsImageService2 vsIconService = ServiceProvider.GlobalProvider.GetService(typeof(SVsImageService)) as IVsImageService2; if (vsIconService == null) { return(null); } try { ImageAttributes imageAttributes = new ImageAttributes { Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WPF, LogicalHeight = sizeY, LogicalWidth = sizeX, StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; IVsUIObject result = vsIconService.GetImage(imageMoniker.Value, imageAttributes); object data; result.get_Data(out data); ImageSource glyph = data as ImageSource; if (glyph != null) { glyph.Freeze(); } return(glyph); } catch { Debug.Fail("Unable to get image."); } return(null); }