/// <summary> /// Adds SampleGrabber for screenshot making. /// </summary> private void AddFilter_SampleGrabber() { // Get the SampleGrabber interface SampleGrabber = new SampleGrabber() as ISampleGrabber; // Configure the sample grabber SampleGrabberFilter = SampleGrabber as IBaseFilter; _pSampleGrabberHelper = new SampleGrabberHelper(SampleGrabber, false); _pSampleGrabberHelper.ConfigureMode(); // Add the sample grabber to the graph int hr = FilterGraph.AddFilter(SampleGrabberFilter, "Sample Grabber"); DsError.ThrowExceptionForHR(hr); return; }
/// <summary> /// Close and dispose all camera and DirectX stuff. /// </summary> public void Dispose() { _bGraphIsBuilt = false; // stop rendering if (MediaControl != null) { try { MediaControl.StopWhenReady(); MediaControl.Stop(); } catch (Exception ex) { Debug.WriteLine(ex); } } if (_bHandlersAdded) { // remove handlers when they are no more needed _bHandlersAdded = false; _DisplayPanel.Paint -= new PaintEventHandler(HostingControl_Paint); _DisplayPanel.Resize -= new EventHandler(HostingControl_ResizeMove); _DisplayPanel.Move -= new EventHandler(HostingControl_ResizeMove); SystemEvents.DisplaySettingsChanged -= new EventHandler(SystemEvents_DisplaySettingsChanged); } // Dispose Managed Direct3D objects if (_pSampleGrabberHelper != null) { _pSampleGrabberHelper.Dispose(); _pSampleGrabberHelper = null; } if (VMRenderer != null) { Marshal.ReleaseComObject(VMRenderer); VMRenderer = null; WindowlessCtrl = null; } if (FilterGraph != null) { Marshal.ReleaseComObject(FilterGraph); FilterGraph = null; MediaControl = null; } if (SmartTee != null) { Marshal.ReleaseComObject(SmartTee); SmartTee = null; } if (SampleGrabber != null) { Marshal.ReleaseComObject(SampleGrabber); SampleGrabber = null; SampleGrabberFilter = null; } if (CaptureFilter != null) { Marshal.ReleaseComObject(CaptureFilter); CaptureFilter = null; } return; }