我是靠谱客的博主 光亮宝马,这篇文章主要介绍详解C#编程获取资源文件中图片的方法,现在分享给大家,希望可以做个参考。

详解C#编程获取资源文件中图片的方法

本文主要介绍C#编程获取资源文件中图片的方法,涉及C#针对项目中资源文件操作的相关技巧,以供借鉴参考。具体内容如下:
例子:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Drawing; namespace CL { public class RES { /// <summary> /// 定义一个资源文件名 资源文件名 = 工程的默认命名空间+文件名(不带扩展名) /// </summary> private string PublicResourceFileName = "CL.Resources"; /// <summary> /// 从资源文件中读取一个资源 /// </summary> /// <param name="resFile">资源文件名称 命名空间+文件名称</param> /// <param name="resName">要读取的资源名称</param> /// <returns>返回一个资源 读取失败返回NULL</returns> public System.Object ReadFromResourceFile(String resName) { try { Assembly myAssembly; myAssembly = Assembly.GetExecutingAssembly(); System.Resources.ResourceManager rm = new System.Resources.ResourceManager(PublicResourceFileName, myAssembly); return rm.GetObject(resName); } catch (Exception ex) { return null; } } /// <summary> /// 获取资源图片 /// </summary> /// <param name="name">文件名</param> /// <returns>资源图片</returns> public Bitmap GetResourceImage(String name) { Object tempbitmap = null; tempbitmap = ReadFromResourceFile(name); if (tempbitmap.GetType().Equals(typeof(Bitmap))) { return (Bitmap)tempbitmap; } return null; } } } //调用GetResourceImage方法即可。name为文件的名称不带有后缀.

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

最后

以上就是光亮宝马最近收集整理的关于详解C#编程获取资源文件中图片的方法的全部内容,更多相关详解C#编程获取资源文件中图片内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(96)

评论列表共有 0 条评论

立即
投稿
返回
顶部