0

I have t his code in the scroll bar event:

if (_fi.Length > 0)
{
    myTrackPanelss1.trackBar1.Minimum = 0;
    myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1;
    tt = list_of_histograms[myTrackPanelss1.trackBar1.Value];
    HistogramGraphs1.DrawHistogram(tt);
    long res = GetTopLumAmount(tt, 1000);
    long max = GetHistogramMaximum(tt);
    GetHistogramAverage(tt);
    setpicture(myTrackPanelss1.trackBar1.Value);
    this.pictureBox1.Refresh();
}

With the following variables defined:

_fi = FileInfo[]
tt = long[]
list_of_histograms = List<long[]>

When i move the bar to the end to the right it's getting to frame 1047 and then throw the exception. When the exception is thrown i see that :

_fi.Length = 1049 (-1 so its 1048) so if its starting from 0 its like 0 to 1047)

list_of_histograms.Count = 1048
myTrackPanelss1.trackBar1.Value = 1048

I know what the exception means the question is why it happend if i,m doing _fi.Length - 1 as length ?

4

2 回答 2

2

该数组_fi可能包含比 更多的项目list_of_histograms。为避免错误,只需根据适当的列表设置最大值:

myTrackPanelss1.trackBar1.Maximum = list_of_histograms.Count - 1;
于 2013-07-10T07:06:59.543 回答
0

您正在尝试获取包含0 到1047 ( ) 元素的列表的第1048个元素 ( )。myTrackPanelss1.trackBar1.Value = 1048list_of_histograms.Count = 1048

显然你的直方图比文件少。这里有什么问题以及真正的修复取决于您的应用程序逻辑。

于 2013-07-10T07:05:35.477 回答