Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 名称为;“新地图”;在当前上下文中不存在_C#_Bitmap - Fatal编程技术网

C# 名称为;“新地图”;在当前上下文中不存在

C# 名称为;“新地图”;在当前上下文中不存在,c#,bitmap,C#,Bitmap,我正试图把调整亮度的事情,但我得到的是不存在于当前上下文错误的“NewBitmap”在这段代码中 picBox.Image = AdjustBrightness(NewBitmap, trackBar1.Value); 这是我的密码 private void trackBar1_Scroll(object sender, EventArgs e) { lblBrightNum.Text = trackBar1.Value.ToString(); picB

我正试图把调整亮度的事情,但我得到的是不存在于当前上下文错误的“NewBitmap”在这段代码中

picBox.Image = AdjustBrightness(NewBitmap, trackBar1.Value);
这是我的密码

private void trackBar1_Scroll(object sender, EventArgs e)
    {
        lblBrightNum.Text = trackBar1.Value.ToString();
        picBox.Image = AdjustBrightness(NewBitmap, trackBar1.Value);
    }



 public static Bitmap AdjustBrightness(Bitmap Image, int Value)
    {
        Bitmap TempBitmap = (Bitmap)Image.Clone();
        float FinalValue = (float)Value / 255.0f;
        Bitmap NewBitmap = new Bitmap(TempBitmap.Width, TempBitmap.Height);
        Graphics NewGraphics = Graphics.FromImage(NewBitmap);
        float[][] FloatColorMatrix ={
                  new float[] {1, 0, 0, 0, 0},
                  new float[] {0, 1, 0, 0, 0},
                  new float[] {0, 0, 1, 0, 0},
                  new float[] {0, 0, 0, 1, 0},
                  new float[] {FinalValue, FinalValue, FinalValue, 1, 1}
             };

        ColorMatrix NewColorMatrix = new ColorMatrix(FloatColorMatrix);
        ImageAttributes Attributes = new ImageAttributes();
        Attributes.SetColorMatrix(NewColorMatrix);
        NewGraphics.DrawImage(TempBitmap, new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, GraphicsUnit.Pixel, Attributes);
        Attributes.Dispose();
        NewGraphics.Dispose();
        return NewBitmap;

    }

您的程序主要包含两种方法,一种是trackBar1_滚动,另一种是AdjustBrightness,visual studio知道AdjustBrightness方法中的“NewBitmap”是什么,但不知道trackBar1_滚动中的“NewBitmap”是什么

 private void trackBar1_Scroll(object sender, EventArgs e)
        {
            lblBrightNum.Text = trackBar1.Value.ToString();
            //Visual studio is complaining about this, you haven't define "NewBitmap", you can fix by adding below:
            Bitmap NewBitmap = //your bitmap
            picBox.Image = AdjustBrightness(NewBitmap, trackBar1.Value);
        }



     public static Bitmap AdjustBrightness(Bitmap Image, int Value)
        {
            Bitmap TempBitmap = (Bitmap)Image.Clone();
            float FinalValue = (float)Value / 255.0f;
            Bitmap NewBitmap = new Bitmap(TempBitmap.Width, TempBitmap.Height);
            Graphics NewGraphics = Graphics.FromImage(NewBitmap);
            float[][] FloatColorMatrix ={
                      new float[] {1, 0, 0, 0, 0},
                      new float[] {0, 1, 0, 0, 0},
                      new float[] {0, 0, 1, 0, 0},
                      new float[] {0, 0, 0, 1, 0},
                      new float[] {FinalValue, FinalValue, FinalValue, 1, 1}
                 };

            ColorMatrix NewColorMatrix = new ColorMatrix(FloatColorMatrix);
            ImageAttributes Attributes = new ImageAttributes();
            Attributes.SetColorMatrix(NewColorMatrix);
            NewGraphics.DrawImage(TempBitmap, new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, GraphicsUnit.Pixel, Attributes);
            Attributes.Dispose();
            NewGraphics.Dispose();
            return NewBitmap;

这是因为您正在将它传递到
AdjustBrightness
,在那里它超出了范围。你是不是想把
picBox.Image
传给别人?我没有领会你的意思。在
trackBar1\u Scroll
中,你试图把
NewBitmap
传给
AdjustBrightness
,但你还没有声明。在我看来,您正在尝试调整
picBox
中图像的亮度,这意味着您应该传入
picBox.image
,而不是
NewBitmap