通过GetManifestResourceStream加载文件出现错误提示“null值”对于“stream”无效

来源:互联网 发布:java printf输出格式 编辑:程序博客网 时间:2024/03/29 14:12

引用地址:http://hi.baidu.com/jiufu/blog/item/43d7cbc8ef06451c7f3e6fcd.html

在做Mobile开发时,需要引入图片,用到了这个方法:

private Bitmap BackgroundImg = newBitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(@"SmartDeviceProject1.bgmain.jpg"));

注:SmartDeviceProject1 :项目名称。bgmain.jpg :图片名称。

编译时候错误提示:“ null值”对于“stream”无效。 低级的错误让我郁闷了一天,最终解决办法如下:

1,把文件bgmain.jpg添加到项目中(在项目上右键—〉添加—〉添加现有项—〉找到并选择bgmain.jpg)

2,在已经添加到项目中的bgmain.jpg上右键—〉属性—〉生成的操作—〉选择“嵌入的资源”

3,正常运行

==============================================================================

现在就可以用这个图片给mobile的Form窗口绘制背景图片了:

private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(BackgroundImg, 0, 0);

        }

原创粉丝点击