您现在的位置是:首页 > 文章详情

WPF在DLL中读取Resource的方法

日期:2018-08-13点击:430
原文: WPF在DLL中读取Resource的方法

WPF是个用户控件,被WinForm调用。而WinForm是在一个DLL类库中被调用。试了很多方法,都无法将Resource中的图读进程序。用下面的方法总算实现了。

 

/根据图片的名称,从资源中找到它 public static System.Drawing.Bitmap GetPngFromResources(string pngName) { /tp://www.worlduc.com/blog2012.aspx?bid=760294 c#访问Resources.resx中的资源 ResourceManager rmManager = global::AddMenuToRevit2013.Properties.Resources.ResourceManager; object obj = rmManager.GetObject(pngName); if (obj == null) { MessageBox.Show("未找到图片:" + pngName); return null; } System.Drawing.Bitmap b = obj as System.Drawing.Bitmap; if (b != null) { return b; } else { MessageBox.Show("未找到图片:" + pngName); return null; } } // System.Drawing.Bitmap要如何轉換成WPF中可用的ImageSource /tp://www.dotblogs.com.tw/bauann/archive/2013/04/18/101793.aspx public static BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap) { BitmapImage bitmapImage = new BitmapImage(); System.IO.MemoryStream ms = new System.IO.MemoryStream(); bitmap.Save(ms, bitmap.RawFormat); bitmapImage.BeginInit(); bitmapImage.StreamSource = ms; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); bitmapImage.Freeze(); return bitmapImage; }
原文链接:https://yq.aliyun.com/articles/677804
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章