Skip to main content

How to draw an image using the OnVideoFrameBuffer event?

Products: Video Capture SDK .Net, Video Edit SDK .Net, Media Player SDK .Net

        // Bitmap loading from file
//private Bitmap logoImage = new Bitmap(@"logo32.png");
private Bitmap logoImage = new Bitmap(@"logo24.jpg");

// Logo RGB24/RGB32 buffer
private IntPtr logoImageBuffer = IntPtr.Zero;
private int logoImageBufferSize = 0;

private void VideoCapture1_OnVideoFrameBuffer(Object sender, VideoFrameBufferEventArgs e)
{
// Create logo buffer if not allocated or have zero size
if (logoImageBuffer == IntPtr.Zero || logoImageBufferSize == 0)
{
if (logoImageBuffer == IntPtr.Zero)
{
if (logoImage.PixelFormat == PixelFormat.Format32bppArgb)
{
logoImageBufferSize = ImageHelper.GetStrideRGB32(logoImage.Width) * logoImage.Height;
logoImageBuffer = Marshal.AllocCoTaskMem(logoImageBufferSize);
}
else
{
logoImageBufferSize = ImageHelper.GetStrideRGB24(logoImage.Width) * logoImage.Height;
logoImageBuffer = Marshal.AllocCoTaskMem(logoImageBufferSize);
}
}
else
{
if (logoImage.PixelFormat == PixelFormat.Format32bppArgb)
{
logoImageBufferSize = ImageHelper.GetStrideRGB32(logoImage.Width) * logoImage.Height;

Marshal.FreeCoTaskMem(logoImageBuffer);
logoImageBuffer = Marshal.AllocCoTaskMem(logoImageBufferSize);
}
else
{
logoImageBufferSize = ImageHelper.GetStrideRGB24(logoImage.Width) * logoImage.Height;

Marshal.FreeCoTaskMem(logoImageBuffer);
logoImageBuffer = Marshal.AllocCoTaskMem(logoImageBufferSize);
}
}

if (logoImage.PixelFormat == PixelFormat.Format32bppArgb)
{
ImageHelper.BitmapToIntPtr(logoImage, logoImageBuffer, logoImage.Width, logoImage.Height,
PixelFormat.Format32bppArgb);
}
else
{
ImageHelper.BitmapToIntPtr(logoImage, logoImageBuffer, logoImage.Width, logoImage.Height,
PixelFormat.Format24bppRgb);
}
}

// Draw image
if (logoImage.PixelFormat == PixelFormat.Format32bppArgb)
{
FastImageProcessing.Draw_RGB32OnRGB24(logoImageBuffer, logoImage.Width, logoImage.Height, e.Frame.Data, e.Frame.Width,
e.Frame.Height, 0, 0);
}
else
{
FastImageProcessing.Draw_RGB24OnRGB24(logoImageBuffer, logoImage.Width, logoImage.Height, e.Frame.Data, e.Frame.Width,
e.Frame.Height, 0, 0);
}

e.UpdateData = true;
}

Required redists

  • SDK redist

Visit our GitHub page to get more code samples.