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;
        }

上一篇:swagger2 2.9.2 请求实体 坑


下一篇:Load、LoadFile、LoadFrom