首页 > Windows开发 > 详细

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

时间:2018-12-24 12:26:38      阅读:182      评论:0      收藏:0      [点我收藏+]
原文: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控件使用

原文:https://www.cnblogs.com/lonelyxmas/p/10167911.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!