C#反射:GetManifestResourceStream
来源:互联网 发布:达瓦黑钢凛怎数据 编辑:程序博客网 时间:2024/06/07 04:39
public virtual Stream GetManifestResourceStream(string name)
参数
- name
- 类型:System.String
所请求的清单资源的名称(区分大小写)。
name格式:项目名称 + 文件名
通过GetManifestResourceStream加载文件出现错误提示“null值”对于“stream”无效。
在做Mobile开发时,需要引入图片,用到了这个方法:
private Bitmap BackgroundImg = new Bitmap(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);
}
using (Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("项目名称.文件名")) { using (StreamReader sr = new StreamReader(stream)) { _usageinfo = sr.ReadToEnd(); } }string version = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName).ProductVersion;
- C#反射:GetManifestResourceStream
- C#反射:GetManifestResourceStream 获取项目资源为空解决方案
- GetManifestResourceStream
- C# GetManifestResourceStream获取资源为null
- C# GetManifestResourceStream获取资源为null
- C# Assembly.GetManifestResourceStream总返回 null问题
- C# 反射
- C#反射
- C# 反射
- C#反射
- C#反射
- C# 反射
- C#反射
- c#反射
- c#反射
- C#反射
- c# 反射
- C# 反射
- ASP.NET C#如何获取当月的第一天和最后一天
- android Notification和NotificationManager的使用
- eclipse android工程前有红色叹号
- 命令设计模式
- git push, error: insufficient permission for adding an object to repository database .git/objects
- C#反射:GetManifestResourceStream
- SGU 253. Theodore Roosevelt
- SQLite3的各个函数(全)
- sql server性能分析--查看当前执行的SQL
- linux 打tar包
- php 无线级别分类 实现评论回复功能
- 使用Lua脚本进行游戏开发(基础篇)
- 图像特征提取2: Haar特征
- 【IOS功能实现】之Core Animation动画开发总结(CALayer)