我想從我的資源文件中加載一堆圖像,但出於某種原因我得到FileNotFoundException。圖像名稱是這樣的: 「image01.png」,「image02.png」,...,「image10.png」,image11.png「C#:FileNotFoundException當從資源加載圖像
最後,我希望能夠顯示所有在屏幕上的圖像
以下是我有:
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。」到「PicturePuzzle」,但仍然沒有運氣。
什麼是您的「資源文件」,它存儲在哪裏以及您的代碼與該資源文件相關的執行位置? –
嵌入式資源文件內置到輸出組件中。在這段代碼中,你認爲你是在告訴計算機在程序集中尋找文件?您似乎試圖從文件系統加載它們。 – adv12
@ adv12:它看起來並不像他試圖加載嵌入式資源,而是從磁盤加載.png文件。 –