如果我问一个愚蠢的问题,我是编程的新手,请原谅我。
我试图显示我从实时相机获得的实时图像。当我启动程序时,图片框能够显示对象(参见图1)。当我删除对象时,它会显示此图像(参见图2)。但问题是当我放回物体时,我应该能够得到一个类似于picture1的图像,但它看起来像picture2。是因为pictureBox不能正常刷新吗?
//R Mode Tab
private void RModeToolStripMenuItem_Click(object sender, EventArgs e)
{
// There is a method, which will obtain the data value and pass to this drawpix
drawPix(x, y, (int)data, (int)data, (int)data);
pictureBox.Refresh();
// Release camera buffer
camera.Release();
}
private void drawPix(int x, int y, int r, int g, int b)
{
((Bitmap)pictureBox.Image).SetPixel(x, y, Color.FromArgb(r, g, b));
return;
}
对我来说,似乎一旦“黑色”被绘制到pictureBox,它似乎无法消失。
您需要将所有绘图逻辑放在图片框的绘图事件中。当此事件触发时,所有内容都将重新绘制。手动提升此调用picturebox.Invalidate()。
因此,将drawPix内容放入paint事件中,并使用按钮单击中的picturebox.Invalidate()强制刷新图片框。