博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

GetManifestResourceStream的使用

Posted on 2011-02-11 17:04  amey  阅读(3289)  评论(0)    收藏  举报
VB.Net中资源的名称为:项目默认命名空间.资源文件名

C#中则是:项目命名空间.资源文件所在文件夹名.资源文件名

例:
[C# code]
Assembly assm = this.GetType().Assembly.GetExecutingAssembly();
istr = assm.GetManifestResourceStream("项目命名空间.资源文件所在文件夹名.资源文件名");
eg:

 public Bitmap LoadBitmap(string imageName, int width, int height)
        {
            return LoadBitmap(this.GetType().Assembly.GetManifestResourceStream("Sample.Images." + imageName + ScreenFactorSuffix + ".png"), width, height);
        }

        public Bitmap LoadBitmap(Stream s, int width, int height)
        {
            Bitmap dib = new Bitmap(s);
            Bitmap ddb = new Bitmap(width * ScreenFactor, height * ScreenFactor);
            Graphics g = Graphics.FromImage(ddb);
            g.DrawImage(dib, new Rectangle(0, 0, width * ScreenFactor, height * ScreenFactor), new Rectangle(0, 0, dib.Width, dib.Height), GraphicsUnit.Pixel);
            dib.Dispose();
            return ddb;
        }