C# 获取Resources


        /// <summary>
        /// 得到要绘置的图片对像
        /// </summary>
        /// <param name="str">图像在程序集中的地址</param>
        /// <returns></returns>
        public static Bitmap GetResBitmap(string str)
        {
           
            Stream sm = FindStream(str);
            if (sm == null) return null;
            return new Bitmap(sm);
        }

        /// <summary>
        /// 得到图程序集中的图片对像
        /// </summary>
        /// <param name="str">图像在程序集中的地址</param>
        /// <returns></returns>
        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(str);
                }
            }
            return null;
        }
  /// <summary>
        /// 获取图像
        /// </summary>
        public static Image GetBitmap(string name)
        {
            object obj = Properties.Resources.ResourceManager.GetObject(name,Properties.Resources.Culture);
            return (Image)obj;
        }

C# 获取Resources

上一篇:C# .exe和.dll文件图标资源提取工具


下一篇:Windows下如何用virtualenv创建虚拟环境