渲染图像而不创建Bitmap / WritableBitmap C#

时间:2018-02-08 14:48:39

标签: c# wpf ffmpeg bitmap

我使用ffmpeg解码H.264流。我有一个指向内存中图像数据的指针,我可以使用以下代码创建WritableBitmap:

     var _rmlive = new WriteableBitmap(e.Width, e.Hieght, 1, 1, PixelFormats.Bgr24, null);
_rmlive.WritePixels(_rectLive, e.PointerToBuffer, _arraySize, e.Stride);

我可以使用以下代码从指针中获取一个Bitmap对象:

byte[] inBytes = new byte[size];
        Marshal.Copy(ptr, inBytes, 0, (int)size);
            var b = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            var BoundsRect = new System.Drawing.Rectangle(0, 0, width, height);
            BitmapData bmpData = b.LockBits(BoundsRect,
                                            ImageLockMode.WriteOnly,
                                            b.PixelFormat);
            IntPtr ptr = bmpData.Scan0;
            int bytes = bmpData.Stride * b.Height;
            try
            {
                Marshal.Copy(inBytes, 0, ptr, bytes);
            }
            catch (Exception e)
            {
            }
            finally
            {
                b.UnlockBits(bmpData);
            }

然后我可以在WPF中渲染和显示它,但它消耗了大量的CPU资源(特别是对于全高清帧)。 问题是可以直接从指针渲染/显示图像而无需在c#/ WPF中创建Bitmap / WritableBitmap吗?

0 个答案:

没有答案
相关问题