WPF在DLL中读取Resource的方法
2014-06-25 18:24
302 查看
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; }
相关文章推荐
- 读取应用程序/类库配置文件(比如***.dll.config)的方法小结
- 利用反射机制,读取dll,并调用其中的方法
- WPF项目中读取图片资源,属性为生成操作为Resource
- 读取resource资源目录下文件的方法
- 关于Object.class.getResourceAsStream方法读取文件的使用
- 导出.net编写的exe/dll文件中Resource的方法
- [XAML]类似WPF绑定的Binding的读取方法
- [总结]读取应用程序/类库配置文件(比如***.dll.config)的方法小结
- 一种强行指定dll assembly读取其相应*.dll.config配置文件的方法(又名:如何创建.net 的DCOM)
- 针对盘古dll重写词库读取 及新词增删改查方法
- 针对盘古dll重写词库读取 及新词增删改查方法
- WPF程序将DLL嵌入到EXE的两种方法
- 读取应用程序/类库配置文件(比如***.dll.config)的方法小结
- 种强行指定dll assembly读取其相应*.dll.config配置文件的方法(又名:如何创建.net 的DCOM)
- WPF 绑定StaticResource到控件的方法
- (wpf)利用dll存放图片并在程序中读取
- java读取resource目录下文件的方法示例
- WPF程序将DLL嵌入到EXE的两种方法
- 如何读取dll里资源文件 的几种方法
- 种强行指定dll assembly读取其相应*.dll.config配置文件的方法(又名:如何创建.net 的DCOM)(转自:http://blog.csdn.net/shaily/article)