void AddSampleGrabber()
{
int hr = 0;
// Add the sample grabber to the graph
hr = graphBuilder.AddFilter(grabberFilter, "NewTOAPIA Grabber");
DsError.ThrowExceptionForHR(hr);
// After the filter is added to the graph, and before
// it is connected to anything, we need to set the format
// and size that we expect.
AMMediaType mt = new AMMediaType();
// Set the media type to Video/RBG24
mt.majorType = MediaType.Video;
mt.subType = MediaSubType.RGB24;
mt.formatType = FormatType.VideoInfo; // What format do we want to use to describe the media
//VIDEOINFOHEADER vih = new VIDEOINFOHEADER();
//vih.BmiHeader.biBitCount = 24;
//vih.BmiHeader.biClrImportant = 0;
//vih.BmiHeader.biClrUsed = 0;
//vih.BmiHeader.biCompression = 0;
//vih.BmiHeader.biHeight = fDesiredHeight;
//vih.BmiHeader.biPlanes = 1;
//vih.BmiHeader.biSize = Marshal.SizeOf(vih);
//vih.BmiHeader.biSizeImage = (uint)(fDesiredWidth * fDesiredHeight * 3); // It's very important to set this one or things won't be right
//vih.BmiHeader.biWidth = fDesiredWidth;
//vih.BmiHeader.biXPelsPerMeter = 0;
//vih.BmiHeader.biYPelsPerMeter = 0;
//// turn the structure back into a pointer
//mt.formatPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(vih));
//mt.formatSize = Marshal.SizeOf(vih);
//mt.formatType = FormatType.VideoInfo;
//Marshal.StructureToPtr(vih, mt.formatPtr, false);
hr = sampleGrabber.SetMediaType(mt);
DsError.ThrowExceptionForHR(hr);
// Free the media type object because we're done with it
mt.Dispose();
mt = null;
// Final sample grabber configuration
hr = sampleGrabber.SetOneShot(false);
hr = sampleGrabber.SetBufferSamples(false);
hr = sampleGrabber.SetCallback(fGrabber, 1);
DsError.ThrowExceptionForHR(hr);
}