public static ImageSource GetIconForImageMoniker(ImageMoniker imageMoniker) { IVsImageService2 imageService = VsAppShell.Current.GlobalServices.GetService <IVsImageService2>(typeof(SVsImageService)); ImageSource glyph = null; ImageAttributes imageAttributes = new ImageAttributes(); imageAttributes.Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags; imageAttributes.ImageType = (uint)_UIImageType.IT_Bitmap; imageAttributes.Format = (uint)_UIDataFormat.DF_WPF; imageAttributes.LogicalHeight = 16; // IconHeight, imageAttributes.LogicalWidth = 16; // IconWidth, imageAttributes.StructSize = Marshal.SizeOf(typeof(ImageAttributes)); IVsUIObject result = imageService.GetImage(imageMoniker, imageAttributes); Object data = null; if (result.get_Data(out data) == VSConstants.S_OK) { glyph = data as ImageSource; if (glyph != null) { glyph.Freeze(); } } return(glyph); }
private static ImageSource GetImage(IVsImageService2 imageService, ImageMoniker imageMoniker) { var imageAttributes = new ImageAttributes { ImageType = (uint)_UIImageType.IT_Bitmap, Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, Format = (uint)_UIDataFormat.DF_WPF, LogicalHeight = 16, LogicalWidth = 16, StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; IVsUIObject uiObject = imageService.GetImage(imageMoniker, imageAttributes); object data; if (uiObject.get_Data(out data) != VSConstants.S_OK) { return(null); } var imageSource = data as ImageSource; imageSource?.Freeze(); return(imageSource); }
/// <summary> /// Converts the given <paramref name="imageMoniker"/> to its <see cref="BitmapSource"/> counterpart. /// </summary> /// <param name="imageMoniker">The image moniker.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="visualStudioImageService">The visual studio image service.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentOutOfRangeException"> /// Must be a positive, non-zero value /// or /// Must be a positive, non-zero value /// </exception> public static BitmapSource ToBitmapSource(this ImageMoniker imageMoniker, int width, int height, IVsImageService2 visualStudioImageService) { // based on https://github.com/madskristensen/ExtensibilityTools/blob/master/src/Misc/Commands/ImageMonikerDialog.xaml.cs#L47 if (visualStudioImageService == null) throw new ArgumentNullException(nameof(visualStudioImageService)); if (width <= 0) throw new ArgumentOutOfRangeException(nameof(width), "Must be a positive, non-zero value"); if (height <= 0) throw new ArgumentOutOfRangeException(nameof(height), "Must be a positive, non-zero value"); if (Microsoft.VisualStudio.Imaging.ExtensionMethods.IsNullImage(imageMoniker)) return null; ImageAttributes imageAttributes = new ImageAttributes { Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WPF, LogicalHeight = height, LogicalWidth = width, StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; IVsUIObject result = visualStudioImageService.GetImage(imageMoniker, imageAttributes); object data; result.get_Data(out data); return data as BitmapSource; }
private static ImageSource LoadImage( IVsImageService2 imageService, ImageMoniker moniker, ref ImageAttributes attributes) { ThreadHelper.ThrowIfNotOnUIThread(); var image = imageService.GetImage(moniker, attributes); ErrorHandler.ThrowOnFailure(image.get_Data(out var data)); return((ImageSource)data); }
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); }
private static bool TryGetImageListAndIndex(this IVsHierarchy hierarchy, IVsImageService2 imageService, uint itemId, out IntPtr imageList, out ushort index) { var itemIdToImageHandle = s_hierarchyToItemIdToImageHandle.GetValue(hierarchy, s_createValue); // Get the actual image moniker that the vs hierarchy is using to in solution explorer. var imageMoniker = imageService.GetImageMonikerForHierarchyItem(hierarchy, itemId, (int)__VSHIERARCHYIMAGEASPECT.HIA_Icon); var monikerImageList = new VsImageMonikerImageList(imageMoniker); // Get an image handle to this image moniker, and keep it around for the lifetime of the // hierarchy itself. var imageHandle = imageService.AddCustomImageList(monikerImageList); itemIdToImageHandle[itemId] = imageHandle; // Now, we want to get an HIMAGELIST ptr for that image. var uiObject = imageService.GetImage(imageHandle.Moniker, new ImageAttributes { StructSize = Marshal.SizeOf(typeof(ImageAttributes)), Dpi = 96, LogicalWidth = 16, LogicalHeight = 16, ImageType = (uint)_UIImageType.IT_ImageList, Format = (uint)_UIDataFormat.DF_Win32, Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, }); if (uiObject != null) { var imageListData = Microsoft.Internal.VisualStudio.PlatformUI.Utilities.GetObjectData(uiObject) as IVsUIWin32ImageList; if (imageListData != null) { int imageListInt; if (ErrorHandler.Succeeded(imageListData.GetHIMAGELIST(out imageListInt))) { imageList = (IntPtr)imageListInt; index = 0; return(true); } } } imageList = default(IntPtr); index = 0; return(false); }
private static bool TryGetImageListAndIndex(this IVsHierarchy hierarchy, IVsImageService2 imageService, uint itemId, out IntPtr imageList, out ushort index) { var itemIdToImageHandle = s_hierarchyToItemIdToImageHandle.GetValue(hierarchy, s_createValue); // Get the actual image moniker that the vs hierarchy is using to in solution explorer. var imageMoniker = imageService.GetImageMonikerForHierarchyItem(hierarchy, itemId, (int)__VSHIERARCHYIMAGEASPECT.HIA_Icon); var monikerImageList = new VsImageMonikerImageList(imageMoniker); // Get an image handle to this image moniker, and keep it around for the lifetime of the // hierarchy itself. var imageHandle = imageService.AddCustomImageList(monikerImageList); itemIdToImageHandle[itemId] = imageHandle; // Now, we want to get an HIMAGELIST ptr for that image. var uiObject = imageService.GetImage(imageHandle.Moniker, new ImageAttributes { StructSize = Marshal.SizeOf(typeof(ImageAttributes)), Dpi = 96, LogicalWidth = 16, LogicalHeight = 16, ImageType = (uint)_UIImageType.IT_ImageList, Format = (uint)_UIDataFormat.DF_Win32, Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, }); if (uiObject != null) { var imageListData = Microsoft.Internal.VisualStudio.PlatformUI.Utilities.GetObjectData(uiObject) as IVsUIWin32ImageList; if (imageListData != null) { int imageListInt; if (ErrorHandler.Succeeded(imageListData.GetHIMAGELIST(out imageListInt))) { imageList = (IntPtr)imageListInt; index = 0; return true; } } } imageList = default(IntPtr); index = 0; return false; }
public BitmapSource GetFolderIcon(bool isExpanded) { var folderImageMoniker = isExpanded ? KnownMonikers.FolderOpened : KnownMonikers.FolderClosed; var vsImage = _vsImageService.GetImage(folderImageMoniker, new ImageAttributes { StructSize = Marshal.SizeOf(typeof(ImageAttributes)), ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WPF, LogicalWidth = 16, LogicalHeight = 16, Background = 0xFFFFFFFF, Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags | unchecked ((uint)_ImageAttributesFlags.IAF_Background) }); var image = vsImage as WpfPropertyValue; return(image?.Value as BitmapSource); }
/// <summary> /// Load and display an image moniker in a PictureBox /// </summary> private void LoadMoniker(object sender, EventArgs e) { IVsImageService2 imageService = (IVsImageService2)OptionsPagePackageCS.GetGlobalService(typeof(SVsImageService)); ImageAttributes attributes = new ImageAttributes { StructSize = Marshal.SizeOf(typeof(ImageAttributes)), ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WinForms, LogicalWidth = 32, LogicalHeight = 32, // Desired RGBA color, don't set IAF_Background below unless you also use this Background = 0xFFFFFFFF, // (uint)(_ImageAttributesFlags.IAF_RequiredFlags | _ImageAttributesFlags.IAF_Background) Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, }; IVsUIObject uIObj = imageService.GetImage(KnownMonikers.Search, attributes); bitmapPictureBox.Image = (Bitmap)GelUtilities.GetObjectData(uIObj); }
public static BitmapSource ToBitmap(this ImageMoniker moniker, int size) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); _imageService = _imageService ?? ServiceProvider.GlobalProvider.GetService <SVsImageService, IVsImageService2>(); var imageAttributes = new ImageAttributes { Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WPF, LogicalHeight = size, LogicalWidth = size, StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; IVsUIObject result = _imageService.GetImage(moniker, imageAttributes); result.get_Data(out object data); return(data as BitmapSource); }
/// <summary> /// Converts an ImageMoniker to an IVsUIObject in the specified size. /// </summary> public static async Task <IVsUIObject> ToUiObjectAsync(this ImageMoniker moniker, int size) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsImageService2 imageService = await AsyncServiceProvider.GlobalProvider.GetServiceAsync <SVsImageService, IVsImageService2>(); Color backColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey); var imageAttributes = new ImageAttributes { Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags | unchecked ((uint)_ImageAttributesFlags.IAF_Background), ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WPF, Dpi = 96, LogicalHeight = size, LogicalWidth = size, Background = (uint)backColor.ToArgb(), StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; return(imageService.GetImage(moniker, imageAttributes)); }
private Icon GetWarningIcon() { if (WarningIcon == null) { ImageAttributes attributes = new ImageAttributes { StructSize = Marshal.SizeOf(typeof(ImageAttributes)), ImageType = (uint)_UIImageType.IT_Icon, Format = (uint)_UIDataFormat.DF_WinForms, LogicalWidth = 16, LogicalHeight = 16, Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags }; IVsImageService2 imageService = (IVsImageService2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsImageService)); IVsUIObject uIObj = imageService.GetImage(KnownMonikers.StatusWarning, attributes); WarningIcon = (Icon)GelUtilities.GetObjectData(uIObj); } return(WarningIcon); }
public static BitmapSource GetImage(ImageMoniker moniker) { var imageAttributes = new ImageAttributes() { Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WPF, LogicalHeight = 16, LogicalWidth = 16, StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; IVsUIObject result = _imageService.GetImage(moniker, imageAttributes); result.get_Data(out object data); if (data == null) { return(null); } return(data as BitmapSource); }
public static IVsImageService2 Create() { IVsImageService2 svc = Substitute.For <IVsImageService2>(); IImageHandle h = ImageHandleMock.Create(); svc.AddCustomImage(null).ReturnsForAnyArgs(h); svc.AddCustomImageList(null).ReturnsForAnyArgs(h); IVsUIObject uiObj = VsUiObjectMock.Create(); svc.GetImage(Arg.Any <ImageMoniker>(), Arg.Any <ImageAttributes>()).ReturnsForAnyArgs(uiObj); svc.GetImageMonikerForFile(null).ReturnsForAnyArgs(KnownMonikers.AboutBox); svc.GetImageMonikerForHierarchyItem(null, 0u, 0).ReturnsForAnyArgs(KnownMonikers.AboutBox); svc.GetImageMonikerForName(null).ReturnsForAnyArgs(KnownMonikers.AboutBox); svc.GetImageMonikerType(Arg.Any <ImageMoniker>()).ReturnsForAnyArgs(0u); IVsImageMonikerImageList mock = VsImageMonikerImageListMock.Create(); svc.CreateMonikerImageListFromHIMAGELIST(IntPtr.Zero).ReturnsForAnyArgs(mock); svc.GetImageListImageMonikers(Arg.Any <ImageMoniker>()).ReturnsForAnyArgs(mock); return(svc); }
//public IVsImageService2 ImageService { get; set; } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ImageMoniker imageMoniker = new ImageMoniker { Guid = JFrogManifestGuid, Id = 10 }; IVsImageService2 imageService = (IVsImageService2)Package.GetGlobalService(typeof(SVsImageService)); ImageAttributes attributes = new ImageAttributes { StructSize = Marshal.SizeOf(typeof(ImageAttributes)), // IT_Bitmap for Bitmap, IT_Icon for Icon ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WinForms, LogicalWidth = 16, LogicalHeight = 16, // Desired RGBA color, if you don't use this, don't set IAF_Background below Background = 0xFFFFFFFF, Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, }; IVsUIObject uIObj = imageService.GetImage(imageMoniker, attributes); return((BitmapImage)GelUtilities.GetObjectData(uIObj)); // return new ImageMoniker { Guid = JFrogManifestGuid, Id = 20 }; }
public static ImageSource GetImage(this ImageMoniker imageMoniker) { IVsImageService2 vsIconService = ServiceProvider.GlobalProvider.GetService(typeof(SVsImageService)) as IVsImageService2; ImageAttributes imageAttributes = new ImageAttributes(); imageAttributes.Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags; imageAttributes.ImageType = (uint)_UIImageType.IT_Bitmap; imageAttributes.Format = (uint)_UIDataFormat.DF_WPF; imageAttributes.LogicalHeight = 16; //IconHeight, imageAttributes.LogicalWidth = 16; //IconWidth, imageAttributes.StructSize = Marshal.SizeOf(typeof(ImageAttributes)); IVsUIObject result = vsIconService.GetImage(imageMoniker, imageAttributes); object data; result.get_Data(out data); ImageSource glyph = data as ImageSource; glyph.Freeze(); return(glyph); }
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)); IVsUIObject result = _imageService.GetImage(moniker, imageAttributes); object data; result.get_Data(out data); if (data == null) { return(null); } return(data as BitmapSource); }
public static BitmapSource ToBitmap(this ImageMoniker moniker, int size) { ThreadHelper.ThrowIfNotOnUIThread(); IVsImageService2 imageService = ServiceProvider.GlobalProvider.GetService <SVsImageService, IVsImageService2>(); Color backColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey); var imageAttributes = new ImageAttributes { Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags | unchecked ((uint)_ImageAttributesFlags.IAF_Background), ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WPF, LogicalHeight = size, LogicalWidth = size, Background = (uint)backColor.ToArgb(), StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; IVsUIObject result = imageService.GetImage(moniker, imageAttributes); result.get_Data(out var data); return(data as BitmapSource); }
private void SaveImagesToDisk(string folder) { PropertyInfo[] monikers = typeof(KnownMonikers).GetProperties(BindingFlags.Static | BindingFlags.Public); ImageAttributes imageAttributes = new ImageAttributes(); imageAttributes.Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags; imageAttributes.ImageType = (uint)_UIImageType.IT_Bitmap; imageAttributes.Format = (uint)_UIDataFormat.DF_WPF; imageAttributes.LogicalHeight = 16; imageAttributes.LogicalWidth = 16; imageAttributes.StructSize = Marshal.SizeOf(typeof(ImageAttributes)); WriteableBitmap sprite = null; int count = 0; char letter = ' '; foreach (var monikerName in monikers) { ImageMoniker moniker = (ImageMoniker)monikerName.GetValue(null, null); IVsUIObject result = _imageService.GetImage(moniker, imageAttributes); if (monikerName.Name[0] != letter) { if (sprite != null) { sprite.Unlock(); SaveBitmapToDisk(sprite, Path.Combine(folder, "_sprites", letter + ".png")); } int items = monikers.Count(m => m.Name[0] == monikerName.Name[0]); sprite = new WriteableBitmap(16, 16 * (items), 96, 96, PixelFormats.Pbgra32, null); sprite.Lock(); letter = monikerName.Name[0]; count = 0; } Object data; result.get_Data(out data); if (data == null) { continue; } BitmapSource glyph = data as BitmapSource; string fileName = Path.Combine(folder, monikerName.Name + ".png"); int stride = glyph.PixelWidth * (glyph.Format.BitsPerPixel / 8); byte[] buffer = new byte[stride * glyph.PixelHeight]; glyph.CopyPixels(buffer, stride, 0); sprite.WritePixels(new Int32Rect(0, count, glyph.PixelWidth, glyph.PixelHeight), buffer, stride, 0); count += 16; SaveBitmapToDisk(glyph, fileName); } // Save the last image sprite to disk sprite.Unlock(); SaveBitmapToDisk(sprite, Path.Combine(folder, "_sprites", letter + ".png")); }
private static ImageSource GetImage(IVsImageService2 imageService, ImageMoniker imageMoniker) { var imageAttributes = new ImageAttributes { ImageType = (uint)_UIImageType.IT_Bitmap, Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, Format = (uint)_UIDataFormat.DF_WPF, LogicalHeight = 16, LogicalWidth = 16, StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; IVsUIObject uiObject = imageService.GetImage(imageMoniker, imageAttributes); object data; if (uiObject.get_Data(out data) != VSConstants.S_OK) { return null; } var imageSource = data as ImageSource; imageSource?.Freeze(); return imageSource; }