码迷,mamicode.com
首页 > 其他好文 > 详细

GetManifestResourceStream得到的Stream是null的解决

时间:2016-08-29 17:44:12      阅读:587      评论:0      收藏:0      [点我收藏+]

标签:

GetManifestResourceStream得到的Stream是null的解决

Ans: 参考

 

http://blog.csdn.net/blue_sky_blue_heart/archive/2005/12/17/555139.aspx

 

 
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
// Note that the name for the embedded resource is case sensitive and must match the file name.
Bitmap bmp = new Bitmap(asm.GetManifestResourceStream(asm.GetName().Name + "." + "pic.png"));
e.Graphics.DrawImage(bmp, 5, 8, new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
 

 

 

 

其实最主要的是在将图片资源的属性设置为“嵌入的资源”:“属性-生成操作-嵌入的资源”

注意GetManifestResourceStream函数的参数:asm.GetName().Name获得的只是当前命名空间的名称,如果在“pic.png”图片在当前工程的Photo目录下,那么该参数就该写成asm.GetName().Name + "." + "Photo" + "." + " pic.png"

 

GetManifestResourceStream得到的Stream是null的解决

标签:

原文地址:http://www.cnblogs.com/Wongss/p/5818643.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!