public Bitmap GetFrame()
{
//TODO: Verify any possible leaks.
//Asks for the buffer size.
int bufferSize = 0;
SampGrabber.GetCurrentBuffer(ref bufferSize, IntPtr.Zero);
//Allocs the byte array.
var handleObj = GCHandle.Alloc(_savedArray, GCHandleType.Pinned);
//Gets the addres of the pinned object.
var address = handleObj.AddrOfPinnedObject();
//Puts the buffer inside the byte array.
SampGrabber.GetCurrentBuffer(ref bufferSize, address);
//Image size.
int width = _videoInfoHeader.BmiHeader.Width;
int height = _videoInfoHeader.BmiHeader.Height;
int stride = width * 3;
//address += (height - 1) * stride;
address += height * stride;
var bitmap = new Bitmap(width, height, -stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, address);
handleObj.Free();
return bitmap;
}