GetManifestResourceStream得到的Stream是null的解决

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"

 

转载于:https://www.cnblogs.com/Wongss/p/5818643.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值