WPF 從程序集中檢索圖片資源stream給Image控件使用
阿新 • • 發佈:2018-12-24
pcre ima lns prism art 箭頭 tro 程序集 apc 原文:WPF 從程序集中檢索圖片資源stream給Image控件使用
版權聲明:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/nihang1234/article/details/82656076
// 獲取當前程序集
Assembly assembly = Assembly.GetAssembly(GetType());
// 獲取程序集中資源名稱
string resourceName = assembly.GetName().Name + ".g";
// 資源管理器
ResourceManager rm = new ResourceManager(resourceName, assembly);
BitmapImage bitmap = new BitmapImage();
using (ResourceSet set = rm.GetResourceSet(CultureInfo.CurrentCulture, true , true))
{
UnmanagedMemoryStream s;
s = (UnmanagedMemoryStream)set.GetObject("images/leaf.jpg", true);
// img在XAML聲明的空間
img.Source=BitmapFrame.Create(s,BitmapCreateOptions.None,BitmapCacheOption.OnLoad);
}
WPF 從程序集中檢索圖片資源stream給Image控件使用