-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAssetCache.cs
More file actions
65 lines (55 loc) · 2.02 KB
/
AssetCache.cs
File metadata and controls
65 lines (55 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.VisualStudio.Imaging.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using ImageAttributes = Microsoft.VisualStudio.Imaging.Interop.ImageAttributes;
namespace ToolWindow
{
public static class AssetCache
{
private static readonly ConcurrentDictionary<string, BitmapSource> Cache = new ConcurrentDictionary<string, BitmapSource>(StringComparer.Ordinal);
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;
}
}
}