Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.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# 在使用Forge的WPF应用程序中,CPU消耗了整个CPU功耗的60%到70%_C#_.net_Wpf_Aforge - Fatal编程技术网

C# 在使用Forge的WPF应用程序中,CPU消耗了整个CPU功耗的60%到70%

C# 在使用Forge的WPF应用程序中,CPU消耗了整个CPU功耗的60%到70%,c#,.net,wpf,aforge,C#,.net,Wpf,Aforge,我正在我的双核2.0GHz笔记本电脑上运行RGE.net提供的摄像头测试样本,该笔记本电脑带有2GB内存。现在,当应用程序开始显示来自摄像头的图像时,我看到了大量的CPU使用。它目前消耗了整个CPU的60%到70% 有人能告诉我为什么它会消耗那么多CPU,我如何才能避免它?我必须构建一个类似的应用程序,它需要摄像头视觉,我将使用C# 在这种方法中,CPU消耗更多 public void cam_NewFrame(object sender, NewFrameEventArgs eventArgs

我正在我的双核2.0GHz笔记本电脑上运行RGE.net提供的摄像头测试样本,该笔记本电脑带有2GB内存。现在,当应用程序开始显示来自摄像头的图像时,我看到了大量的CPU使用。它目前消耗了整个CPU的60%到70%

有人能告诉我为什么它会消耗那么多CPU,我如何才能避免它?我必须构建一个类似的应用程序,它需要摄像头视觉,我将使用C#

在这种方法中,CPU消耗更多

public void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{

    Bitmap imgforms = (Bitmap)eventArgs.Frame.Clone();

    h = imgforms.Height;
    w = imgforms.Width;
    //video = (Bitmap)eventArgs.Frame.Clone();

    BitmapImage bi = new BitmapImage();
    bi.BeginInit();

    MemoryStream ms = new MemoryStream();
    imgforms.Save(ms, ImageFormat.Bmp);
    ms.Seek(0, SeekOrigin.Begin);

    bi.StreamSource = ms;

    bi.EndInit();
    bi.Freeze();

    Dispatcher.Invoke(new ThreadStart(delegate
    {
        cam_image.Source = bi;//GetBitmapImage(imgforms);
    }));
    //bi = null;

    // BitmapSource bi = Convert(video);
    if(statusText == "Stop Record")
    {
        // AVIwriter.Quality = 0;
        avwriter.AddFrame(imgforms);
    }
}

这是因为图像处理是非常CPU密集型的,而且你的笔记本电脑不是很高端。你可以试试。@Clemens我已经用过你的方法,但对我不起作用。