You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
44 lines
1.0 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Drawing; |
|
using System.Windows; |
|
using System.Windows.Interop; |
|
using System.Windows.Markup; |
|
using System.Windows.Media.Imaging; |
|
|
|
using ICSharpCode.Core.WinForms; |
|
|
|
namespace ICSharpCode.WpfDesign.AddIn |
|
{ |
|
class GetBitmapExtension : MarkupExtension |
|
{ |
|
public GetBitmapExtension(string key) |
|
{ |
|
this.key = key; |
|
} |
|
|
|
static Dictionary<string, BitmapSource> cache = new Dictionary<string, BitmapSource>(); |
|
|
|
protected string key; |
|
|
|
public override object ProvideValue(IServiceProvider sp) |
|
{ |
|
lock (cache) { |
|
BitmapSource result; |
|
if (!cache.TryGetValue(key, out result)) { |
|
result = GetBitmapSource(); |
|
result.Freeze(); |
|
cache[key] = result; |
|
} |
|
return result; |
|
} |
|
} |
|
|
|
BitmapSource GetBitmapSource() |
|
{ |
|
Bitmap bitmap = WinFormsResourceService.GetBitmap(key); |
|
return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, |
|
Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); |
|
} |
|
} |
|
}
|
|
|