在WPF图像中快速显示System.Drawing.Image

时间:2015-02-10 11:57:47

标签: c# wpf system.drawing bitmapimage

我需要将网络摄像头图片(由AForge检索)转换为BitmapImage,以便将其用作WPF图像控件的源。

以下来源正在运行,但它仅在第3代i7上以5-7 FPS运行。

是否有更好的替代方案来提高速度?

    void videoSource_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
    {

        System.Drawing.Image img = eventArgs.Frame;
        BitmapImage bitmapImage;

        using (MemoryStream memory = new MemoryStream())
        {

            img.Save(memory, ImageFormat.Bmp);
            bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            memory.Seek(0, SeekOrigin.Begin);
            bitmapImage.StreamSource = memory;
            bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
            bitmapImage.EndInit();
        }

        bitmapImage.Freeze();
        Dispatcher.BeginInvoke(new ThreadStart(delegate
        {
            outputImage.Source = bitmapImage;
        }));
    }

0 个答案:

没有答案