我正在创建一个软件,其中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;
}
答案 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#