WPF 从程序集中检索图片资源stream给Image控件使用

2023-04-24,,

原文: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控件使用的相关教程结束。

《WPF 从程序集中检索图片资源stream给Image控件使用.doc》

下载本文的Word格式文档,以方便收藏与打印。