PictureBox没有正常刷新? [英] PictureBox not refreshing properly?

查看:123
本文介绍了PictureBox没有正常刷新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我问一个愚蠢的问题,我是编程的新手,原谅我。

I am new to programming pardon me if i am asking a dumb question.

我试图显示我从实时相机中获得的实时图像。当我启动程序时,图片框能够显示该对象(参见图1)。当我删除对象时,它会显示此图像(参见图2)。但问题是,当我放回物体时,我应该能够得到一个类似于picture1的图像,但它看起来像picture2。
是因为pictureBox没有正确刷新?

I am trying to display real time image that i obtained from a live camera. When i start the program, the picturebox is able to show the object(refer to picture1). When i remove the object, it display this image(refer to picture2). But the problem is that when i put back the object, i should be able to get an image that is similar to picture1 but instead it look like picture2. Is it because the pictureBox is not refreshing properly?

    //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;
    }

(图1)这是我启动程序时获得的图像

(Picture1)This is the image i get when i start the program

(图2)这是我删除对象后的图像

(Picture2)This is the image after i remove the object

对我而言,似乎曾经将黑色绘制到pictureBox,它似乎无法消失。

To me it seems like once "black" is drawn to the pictureBox, it doesnt seems to be able to go away.

推荐答案

您需要将所有绘图逻辑放在图片框的绘图事件中。当此事件触发时,所有内容都将重新绘制。要手动提升此调用picturebox.Invalidate()。

You need to put all all of your drawing logic in the paint event of the picturebox. Everything will be redrawn when this event fires. To manually raise this call picturebox.Invalidate().

因此将drawPix内容放入paint事件并使用按钮中的picturebox.Invalidate()强制刷新图片框点击。

So put the drawPix stuff into the paint event and force the picturebox to refresh using picturebox.Invalidate() in your button click.

这篇关于PictureBox没有正常刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆