Reputation: 11321
private void button8_Click(object sender, EventArgs e)
{
List<long> averages;
long res = 0;
_fi = new DirectoryInfo(subDirectoryName).GetFiles("*.bmp");
averages = new List<long>(_fi.Length);
for (int i = 0; i < _fi.Length; i++)
{
Bitmap myBitmaps = new Bitmap(_fi[i].Name);
//long[] tt = list_of_histograms[i];
long[] HistogramValues = GetHistogram(myBitmaps);
res = GetTopLumAmount(HistogramValues,1000);
averages.Add(res);
}
}
The exception is on the line:
Bitmap myBitmaps = new Bitmap(_fi[i].Name);
Upvotes: 4
Views: 251
Reputation: 18546
@Lester is the right answer (+1), but I did want to say you could shorten your implementation and make it a little more readable by using some functional programming constructs:
var averages = new DirectoryInfo(subDirectoryName)
.GetFiles("*.bmp")
.Select(t => new Bitmap(t.FullName))
.Select(GetHistogram)
.Select(v => GetTopLumAmount(v, 1000))
.ToList();
Upvotes: 3
Reputation: 26436
Did you try .FullName
? That should include the entire directory.
Upvotes: 1
Reputation: 25201
You're only passing the file name to the Bitmap
constructor, but you should actually pass the full path to the file using _fi[i].FullName
Upvotes: 11