0

我有在 4x2 位图图像数组上运行的方法,并且我正在使用 Parallel.For 循环遍历 8 个图像中的每一个。然后它遍历每个图像中的每个像素并修改每个图像中的每个像素,并返回完整的位图数组。

当我运行该应用程序时,它会很好地生成数组,但是当它到达此代码时,我得到一个“聚合异常”,但从那个错误中我无法弄清楚究竟是什么问题。

某个好心人可以看看这段代码中是否有任何明显的突出之处吗?谢谢。

public Bitmap[,] ParallelImageProcess(Bitmap[,] bmap)
    {

        Parallel.For(0, 3, y =>
        {
            for (int x = 0; x < 2; x++)
            {
                int width = bmap[x, y].Width;
                int height = bmap[x, y].Height;

                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        Color oldPixel = bmap[x, y].GetPixel(i, j);
                        Color newPixel = Color.FromArgb(oldPixel.R, oldPixel.G, 0);
                        bmap[x, y].SetPixel(i, j, newPixel);
                    }

                }

            }

        });
        return bmap;
    }
4

0 回答 0