using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Drawing; using System.Reflection; using System.Windows.Forms; namespace ButtonImages { /// /// /// public class ImageObject { /// /// 得到要绘置的图片对像 /// /// 图像在程序集中的地址 /// public static Bitmap GetResBitmap(string str) { Stream sm; sm = FindStream("", str); if (sm == null) return null; return new Bitmap(sm); } /// /// 得到要绘置的图片对像 /// /// 图像在程序集中的路径 /// 图像在程序集中的地址 /// public static Bitmap GetResBitmap(string path, string str) { Stream sm; sm = FindStream(path, str); if (sm == null) return null; return new Bitmap(sm); } /// /// 获取资源图标 /// /// /// public static Icon GetResIcon(string str) { Stream sm; sm = FindStream(Application.ExecutablePath, str); if (sm == null) return null; return new Icon(sm); } /// /// 得到图程序集中的图片对像 /// /// 图像在程序集中的地址 /// private static Stream FindStream(string str) { Assembly assembly = Assembly.GetExecutingAssembly(); string[] resNames = assembly.GetManifestResourceNames(); foreach (string s in resNames) { if (s == str) { return assembly.GetManifestResourceStream(s); } } return null; } /// /// 得到图程序集中的图片对像 /// /// 图像在程序集中的路径 /// 图像在程序集中的地址 /// private static Stream FindStream(string path, string str) { Assembly assembly = Assembly.GetExecutingAssembly(); if (path != "" && File.Exists(path)) { assembly = Assembly.LoadFile(path); } string[] resNames = assembly.GetManifestResourceNames(); foreach (string s in resNames) { if (s == str) { return assembly.GetManifestResourceStream(s); } } return null; } } }