Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.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中使用FORGE时,当前在其他地方使用#_C#_Visual Studio_Visual Studio 2010_Aforge - Fatal编程技术网

C# 在c中使用FORGE时,当前在其他地方使用#

C# 在c中使用FORGE时,当前在其他地方使用#,c#,visual-studio,visual-studio-2010,aforge,C#,Visual Studio,Visual Studio 2010,Aforge,我在使用DirectShow和Forge从我的网络摄像头中捕获图像并在图片盒中显示时遇到了一些问题,即使尝试了几次,我也总是会遇到同样的错误 这是我的密码 public void video_NewFrame(object sender, NewFrameEventArgs EventArgs) { pictureBox1.Image = (Bitmap)EventArgs.Frame.Clone(); } 但我也试过这个 public void video_N

我在使用DirectShow和Forge从我的网络摄像头中捕获图像并在图片盒中显示时遇到了一些问题,即使尝试了几次,我也总是会遇到同样的错误

这是我的密码

public void video_NewFrame(object sender, NewFrameEventArgs EventArgs)
    {
        pictureBox1.Image = (Bitmap)EventArgs.Frame.Clone();
    }
但我也试过这个

public void video_NewFrame(object sender, NewFrameEventArgs EventArgs)
    {
        lock (EventArgs)
        {
            pictureBox1.Image = (Bitmap)EventArgs.Frame.Clone();
        }
    }
还有这个

public void video_NewFrame(object sender, NewFrameEventArgs EventArgs)
    {
        lock (pictureBox1)
        {
            pictureBox1.Image = (Bitmap)EventArgs.Frame.Clone();
        }
    }
不管我怎么做,我总是会犯这个错误

我的实际代码是这样的,它可以工作,但我不喜欢它,因为它只是一种忽略问题的方法,我想解决这个问题

public void video_NewFrame(object sender, NewFrameEventArgs EventArgs)
    {
        try
        {
            pictureBox1.Image = (Bitmap)EventArgs.Frame.Clone();
        }
        catch 
        {
        }
    }
非常感谢你的帮助。 向您致意,
Sergio David Mercado Vera

我不知道为什么需要这样做,但您应该使用Invoke:

public void video_NewFrame(object sender, NewFrameEventArgs EventArgs)
    {
        Invoke(new Action(() =>
               {
            pictureBox1.Image = (Bitmap)EventArgs.Frame.Clone();
        }));
    }

我不知道为什么这是必要的,但您应该使用Invoke:

public void video_NewFrame(object sender, NewFrameEventArgs EventArgs)
    {
        Invoke(new Action(() =>
               {
            pictureBox1.Image = (Bitmap)EventArgs.Frame.Clone();
        }));
    }