このコードは、保存したテキストファイルからフォルダディレクトリを読み取り、その'activeFilepath'変数を使用してフォルダ内の各ファイルを読み取り、名前を取得することを目的としています。これを使用して、振り向く。
StreamReader textIn = new StreamReader(imageSet);
try
{
//Get the folder location by reading in the specific text file.
activeFilepath = textIn.ReadLine();
//If the user isn't choosing a password then go into the 'Blurred' directory of the folder.
if (choosePassword == false)
activeFilepath = activeFilepath + @"\Blurred";
int i = 0;
//Read in all of the image location strings, and put them in the pictureLocations list.
foreach (string filePath in Directory.EnumerateFiles(activeFilepath))
{
pictureLocations.Add(filePath);
//pictureLocations[i] = filePath;
// Display an error image if there is a blank entry in the picture location.
if (pictureLocations[i] == null)
pictureLocations[i] = @"C:\Users\Public\Pictures\Sample Pictures\error.png";
//Remove Thumbs.db from the list if read in.
if (pictureLocations[i] == activeFilepath + @"\Thumbs.db")
{
pictureLocations.Remove(pictureLocations[i]);
}
i++;
}
foreach (PictureBox imagePanel in pictureBoxList)
{
int rand = randomGenerator.Next(0, pictureLocations.Count);
//The images are then loaded in a random order from the picture location list.
imagePanel.Load(pictureLocations[rand]);
//Remove the picture just loaded out of the list so it won't repeat.
pictureLocations.Remove(pictureLocations[rand]);
imagePanel.SizeMode = PictureBoxSizeMode.StretchImage;
}
現時点では、Thumbs.dbをリストから削除すると(フォームにある画像ボックスにロードしたくないため)、インデックスが範囲外であるというインデックスタイプのエラーが表示されますが、単に読み込ませるだけで、代わりにパラメータタイプのエラーが発生します。
後者はThumbs.dbを画像として読み込もうとしているためだと思いますが、そもそも読み取りを削除または停止する別の方法があるのでしょうか。それはまったく別のものですか?