【发布时间】:2015-12-14 20:22:37
【问题描述】:
我试图从我的资源文件中加载一堆图像,但由于某种原因我得到了 FileNotFoundException。图像名称如下: "image01.png", "image02.png", ... , "image10.png", image11.png"
最后我希望能够在屏幕上显示所有图像。
这是我所拥有的:
String imgName;
int row = 0, col = 0;
for (int i = 1; i <= 15; i++)
{
//get the name of the current image
if (i < 10)
imgName = "image0" + i + ".png";
else
imgName = "image" + i + ".png";
Image img = null;
try {
img = Image.FromFile(imgName);//read the image from the resource file
}
catch (Exception e) { Console.WriteLine("ERROR!!!" + e); }
}
这是我得到的示例错误输出:
ERROR!!!System.IO.FileNotFoundException: tile01.png
at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromFile(String filename)
我还在第 56 行从“PictureForm.PuzzleForm”中修复了一个类型。到“图片拼图”。但仍然没有运气。
【问题讨论】:
-
你的“资源文件”是什么,它存储在哪里,你的代码在哪里执行?
-
嵌入的资源文件被内置到输出程序集中。您认为您在这段代码中的什么位置告诉计算机在程序集中查找文件?您似乎正在尝试从文件系统加载它们。
-
@adv12:看起来他并不是在尝试加载嵌入式资源,而是从磁盘加载 .png 文件。
-
我的资源文件是我的项目文件中的一个文件。路径是这样的:C:\Users\me\blah\Project\MyImageProject\Resources
-
是不是和java很像,你的项目可以有一个res文件夹,你可以把你的图片放进去,然后从那里读取?
标签: c# image resources filenotfoundexception