小莫妮卡 2021-11-24 17:53 采纳率: 0%
浏览 66
已结题

WPF中如何高效刷新多画面

通过ffmpeg解码并渲染到image控件,在渲染多个image时,画面明显变慢,cpu占用也高,有没有别的渲染方案

我试过将DispatcherPriority.Background改成DispatcherPriority.Normal,画面明显变流畅了,但其他交互变得很卡(例如点击别的按钮时,很迟才响应);猜想可能是wpf只有一条ui线程,同时刷新这么多个image画面导致的卡顿。

try
            {
                while (flg)
                {
                    if (d == null) break;
                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        try
                        {
                            ImageSource src = ChangeBitmapToImageSource(new Bitmap(d.avFrame.width, d.avFrame.height, d.avFrame.linesize[0], System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr)d.avFrame.data[0]));
                            if (src != null)
                            {
                                d.image.Source = src;
                            }
                        }
                        catch
                        {
                            flg = false;
                        }
                    }));
                    Thread.Sleep(10);
                }
            }

  • 写回答

2条回答 默认 最新

  • churuxu 2021-11-24 19:09
    关注

    直接找开源的代码参考就行

    https://github.com/search?q=WPF+ffmpeg

    评论

报告相同问题?

问题事件

  • 系统已结题 12月2日
  • 创建了问题 11月24日