I'm using ffmpeg to decode H.264 streams. I have a pointer to image data in memory and i can create a WritableBitmap using this code:
var _rmlive = new WriteableBitmap(e.Width, e.Hieght, 1, 1, PixelFormats.Bgr24, null);
_rmlive.WritePixels(_rectLive, e.PointerToBuffer, _arraySize, e.Stride);
and i can get a Bitmap object out of the pointer using this code:
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);
}
then i can render and display it in WPF but it consumes a lot of CPU resources (specially for full HD frames). the question is it is possible to render/display the image directly from the pointer without creating Bitmap/WritableBitmap in c# / WPF?