AForge.Video.DirectShow.FilterInfo.CreateFilter C# (CSharp) Method

CreateFilter() public static method

Create an instance of the filter.
The returned filter's object should be released using Marshal.ReleaseComObject().
public static CreateFilter ( string filterMoniker ) : object
filterMoniker string Filter's moniker string.
return object
        public static object CreateFilter( string filterMoniker )
        {
            // filter's object
            object filterObject = null;
            // bind context and moniker objects
            IBindCtx bindCtx = null;
            IMoniker moniker = null;

            int n = 0;

            // create bind context
            if ( Win32.CreateBindCtx( 0, out bindCtx ) == 0 )
            {
                // convert moniker`s string to a moniker
                if ( Win32.MkParseDisplayName( bindCtx, filterMoniker, ref n, out moniker ) == 0 )
                {
                    // get device base filter
                    Guid filterId = typeof( IBaseFilter ).GUID;
                    moniker.BindToObject( null, null, ref filterId, out filterObject );

                    Marshal.ReleaseComObject( moniker );
                }
                Marshal.ReleaseComObject( bindCtx );
            }
            return filterObject;
        }

Usage Example

Beispiel #1
0
        public bool GetCameraPropertyRange(CameraControlProperty property, out int minValue, out int maxValue, out int stepSize, out int defaultValue, out CameraControlFlags controlFlags)
        {
            bool flag = true;

            if (deviceMoniker == null || string.IsNullOrEmpty(deviceMoniker))
            {
                throw new ArgumentException("Video source is not specified.");
            }
            lock (sync)
            {
                object obj = null;
                try
                {
                    obj = FilterInfo.CreateFilter(deviceMoniker);
                }
                catch
                {
                    throw new ApplicationException("Failed creating device object for moniker.");
                }
                if (!(obj is IAMCameraControl))
                {
                    throw new NotSupportedException("The video source does not support camera control.");
                }
                IAMCameraControl iAMCameraControl = (IAMCameraControl)obj;
                int range = iAMCameraControl.GetRange(property, out minValue, out maxValue, out stepSize, out defaultValue, out controlFlags);
                flag = (range >= 0);
                Marshal.ReleaseComObject(obj);
                return(flag);
            }
        }
All Usage Examples Of AForge.Video.DirectShow.FilterInfo::CreateFilter