0

please explain to me why the error occurs.

Assignment: I have a method that converts an image to an image with outlines highlighted. As an optimization, I need to process this image in multiple threads.

I came up with an algorithm in which you get the number of threads as input. The algorithm cuts the image into as many parts as there are threads, and each thread processes its own piece of the image.

Image[,] iCells = new Image[xChanks, yChanks];
for (int i = 0; i < xChanks; i++)
{
     for (int j = 0; j < yChanks; j++)
     {
         Thread NewTread = new Thread(() =>
         {
              iCells[i,j] = ConvolutionFilter(new Bitmap(iCells[i,j]), xkernel, ykernel, isColor, gray_value, r, g, b);
         });
         NewTread.Start();
     }
}

But i catch a mistake System.IndexOutOfRangeException: "Index was outside the bounds of the array."

i or j > Chanks. Why the increment in "for" works with an error?

Or maybe I'm not doing it right?

Semyon
  • 13
  • 3

0 Answers0