-3

私はトラックバーのこのスクロールイベントを持っています:

private void trackBar1_Scroll(object sender, EventArgs e)
        {

                trackbarCounter++;
                if (manualDone == true)
                {
                    myTrackPanelss1.trackBar1.Minimum = 0;
                    myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1;                    setpicture(myTrackPanelss1.trackBar1.Value);
                    this.pictureBox1.Refresh();
                }
                if (automaticDone == true)
                {
                    myTrackPanelss1.trackBar1.Minimum = 0;
                    myTrackPanelss1.trackBar1.Maximum = fiAutomatic.Length - 1;
                    long[] tt = list_of_histograms[myTrackPanelss1.trackBar1.Value];
                    long res = GetTopLumAmount(tt, 1000);
                    long max = GetHistogramMaximum(tt);
                    GetHistogramAverage(tt);
                    setpicture(myTrackPanelss1.trackBar1.Value);
                    this.pictureBox1.Refresh();

                                    }

        }

例外は次の行にあります。

long[] tt = list_of_histograms[myTrackPanelss1.trackBar1.Value];

トラックバーをクリックして右に移動した後、この場合はフレーム/トラック40まで移動し、そこで例外をスローしました。

例外:

インデックスが範囲外でした。負ではなく、コレクションのサイズより小さくなければなりません。パラメータ名:インデックス

現在、fiAutomatic 変数には、たとえばインデックス [0] に 2225 個のインデックスが含まれています: {000001.bmp} インデックス [1] には、{000002.bmp} などがあります。

list_of_histograms には、各インデックスに 40 個のインデックスが含まれるようになりました。たとえば、index[0] には 256 個のインデックスがあります。次に、index[1] で再び {[long256]} と別の 256 の数字など。

また、trackBar の値は 40 です。

しかし、40フレーム/画像の後にトラックバーを右に移動すると、この例外がスローされるのはなぜですか?

これは完全な例外メッセージです:

System.ArgumentOutOfRangeException was unhandled
  Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  Source=mscorlib
  ParamName=index
  StackTrace:
       at System.ThrowHelper.ThrowArgumentOutOfRangeException()
       at System.Collections.Generic.List`1.get_Item(Int32 index)
       at Extracting_Frames.Form1.trackBar1_Scroll(Object sender, EventArgs e) in D:\C-Sharp\Extracting_Frames\Extracting_Frames\Extracting_Frames\Form1.cs:line 1793
       at System.Windows.Forms.TrackBar.OnScroll(EventArgs e)
       at System.Windows.Forms.TrackBar.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WmHScroll(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.UserControl.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
       at System.Windows.Forms.Control.DefWndProc(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.TrackBar.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Extracting_Frames.Program.Main() in D:\C-Sharp\Extracting_Frames\Extracting_Frames\Extracting_Frames\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at System.Activator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
4

1 に答える 1

1

list_of_histograms is a contain now 40 indexs in each index

これはあなたの問題でしょう。何かを宣言すると、0からインデックスが付けられることに注意してください。したがって、40のインデックスは、39で最大になることを意味します。これを行うlist_of_histograms[40]と、エラーが発生します。

編集:そして今、私がそれを再タグ付けするために行くとき、私はあなたの質問へのコメントに気づきます...

于 2012-10-31T15:50:42.293 に答える