我在代码中找不到错误。图片框未更新

时间:2019-06-11 13:46:47

标签: c# system.drawing

我正在创建一个软件,其中pictureBox2用单击pictureBox1的像素的颜色进行更新。

已经尝试使用refresh(),但是pictureBox2不变。

private void PictureBox1_MouseUp(object sender, MouseEventArgs e)
{
    Bitmap b = new Bitmap(pictureBox1.Image);
    color = b.GetPixel(e.X, e.Y); // Color

    solidColor = new Bitmap(pictureBox2.Width, pictureBox2.Height, PixelFormat.Format24bppRgb); //Image
    using (Graphics grp = Graphics.FromImage(solidColor))
    {
        SolidBrush co = new SolidBrush(color);
        grp.FillRectangle( co, 0, 0, pictureBox2.Width, pictureBox2.Height);
    }

    pictureBox2.Image = solidColor;
}

1 个答案:

答案 0 :(得分:0)

我能够做到这一点。

private void PictureBox1_Click(object sender, EventArgs e)
        {

            Bitmap b = new Bitmap(pictureBox1.Image);
            MouseEventArgs me = (MouseEventArgs)e;
            Point cord= me.Location;
            color = b.GetPixel(cord.X,cord.Y); 

            solidColor = new Bitmap(pictureBox2.Width, pictureBox2.Height, PixelFormat.Format24bppRgb);
            using (Graphics grp = Graphics.FromImage(solidColor))
            {

                SolidBrush co = new SolidBrush(color);
                grp.FillRectangle(co, 0, 0, pictureBox2.Width, pictureBox2.Height);

            }

            pictureBox2.Image = solidColor;

        }
```c#