C#资源阵列
我有一堆我使用C#项目的图片,我试图对它们进行初始化所有以备后用。有超过50他们和它们都具有相同的名称格式Properties.Resources ._#,其中#是图像编号。我想要做的是这样的:
I have a bunch of pictures I'm using in a C# project, and I'm trying to initialize them all for later use. There are over 50 of them and they all have the same name format Properties.Resources._#, where # is the picture number. What I'm trying to do is something like:
for(int i = 0; i < 100; i++) {
pics[i] = Properties.Resources._i;
}
我怎么会去嵌入的索引,名称?
How would I go about embedding the index into the name?
谢谢,节日快乐
编辑:刚刚意识到,如果我有办法嵌入指数的名义,我可以有一个返回根据给定数量的特定图片,这样将工作太的功能。
Just realized that if I had a way to embed the index in the name, I could just have a function that returns the specific picture based on the number given, so that would work too.
筛选
(Bitmap)Properties.Resources.ResourceManager.GetObject("_" + i)
需要注意的是每次调用将读取位图的单独副本,而且都需要时间。结果
。如果您使用图像频繁,预载他们到一个数组会让你的程序的多的速度更快。
Note that each call will read a separate copy of the bitmap, and will take time.
If you use the images frequently, pre-loading them into an array will make your program much faster.