位图未解析为函数变量

Bitmap not parsed as a function variable

我得到了一些简单的代码来从 5 个位图中获取平均颜色。

    private Bitmap AVG5Bitmaps(Bitmap a, Bitmap b, Bitmap c, Bitmap d, Bitmap e)
    {
        Bitmap result = new Bitmap(c);

        for (int x = 0; x < result.Width; x++) 
        {
            for (int y = 0; y < result.Height; y++) 
            {
                int r = (
                        (int)a.GetPixel(x, y).R + 
                        (int)b.GetPixel(x, y).R +
                        (int)c.GetPixel(x, y).R +
                        (int)d.GetPixel(x, y).R +
                        (int)e.GetPixel(x, y).R) / 5;

                int g = (
                         (int)a.GetPixel(x, y).G +
                         (int)b.GetPixel(x, y).G +
                         (int)c.GetPixel(x, y).G +
                         (int)d.GetPixel(x, y).G +
                         (int)e.GetPixel(x, y).G) / 5;

                int b =  (
                         (int)a.GetPixel(x, y).B +
                         (int)b.GetPixel(x, y).B +
                         (int)c.GetPixel(x, y).B +
                         (int)d.GetPixel(x, y).B +
                         (int)e.GetPixel(x, y).B) / 5;

                  result.SetPixel(x,y,Color.FromArgb(r,g,b))
            }
        }
       return result; 
    }

奇怪的是 a.GetPixel(x, y).R 被识别,但是 b.GetPixel(x, y).R 给出了一个错误:

Cannot use local variable b before it is declared

b连位图对象都不看?我不明白,为什么代码适用于 a 但不适用于 b。这是 Visual Studio 2010 的错误吗?

根据要求用完整的功能代码更新了问题

您的线路:

int b = 

隐藏了参数 b,因此您试图在其赋值范围内访问该变量。因此错误。重命名变量。