我一直在尝试在图像过滤中使用线程池,该方法从图像中取出红色并返回过滤后的图像。当 y 变量达到最大数量时出现错误。我一直在寻找答案,但找不到与此相关的任何内容。
public Color[,] Apply(Color[,] input)
{
int width = input.GetLength(0);
int height = input.GetLength(1);
Color[,] result = new Color[width, height];
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
ThreadPool.QueueUserWorkItem(state => Work(x, y));
}
}
void Work(int x, int y)
{
var p = input[x, y];
result[x, y] = Color.FromArgb(p.A, 0, p.G, p.B);
}
return result;
}
Run Code Online (Sandbox Code Playgroud)