Ejemplo n.º 1
0
        /// <summary>
        /// Sets the preview window.
        /// </summary>
        private void SetPreviewWindow(IntPtr windowHandle)
        {
            // Set capture window
            camWindowHandle = windowHandle;

            try
            {
                // Connect to the capture device
                if(Win32.SendMessage(camWindowHandle, Win32.WM_CAP_DRIVER_CONNECT, 0, 0) == 0)
                    throw new CamException("Could not connect to device.");
                Win32.SendMessage(camWindowHandle, Win32.WM_CAP_SET_PREVIEW, 0, 0);
                Win32.SendMessage(camWindowHandle, Win32.WM_CAP_SET_SCALE, 0, 0);

                // Get device capabilities
                Win32.CapDriverCaps caps = new Win32.CapDriverCaps();
                Win32.SendMessage(camWindowHandle, Win32.WM_CAP_DRIVER_GET_CAPS, Marshal.SizeOf(caps), ref caps);
                hasDlgVideoDisplay = caps.fHasDlgVideoDisplay != 0;
                hasDlgVideoFormat = caps.fHasDlgVideoFormat != 0;
                hasDlgVideoSource = caps.fHasDlgVideoSource != 0;

                // Set callbacks
                frameCallback = new Win32.FrameCallback(FrameCallbackProc);
                if(Win32.SendMessage(camWindowHandle, Win32.WM_CAP_SET_CALLBACK_FRAME, 0, frameCallback) == 0)
                    throw new CamException("Could not set internal device callback.");
            }
            catch
            {
                // Clean up
                Dispose();

                // Forward error
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the preview window.
        /// </summary>
        void SetPreviewWindow(IntPtr windowHandle)
        {
            // Set capture window
            camWindowHandle = windowHandle;

            var success = false;
            try
            {
                // Connect to the capture device
                if (Win32.SendMessage(camWindowHandle, Win32.WM_CAP_DRIVER_CONNECT, 0, 0) == 0)
                    throw new CamException("Could not connect to device.");
                Win32.SendMessage(camWindowHandle, Win32.WM_CAP_SET_PREVIEW, 0, 0);
                Win32.SendMessage(camWindowHandle, Win32.WM_CAP_SET_SCALE, 0, 0);

                // Get device capabilities
                var caps = new Win32.CapDriverCaps();
                Win32.SendMessage(camWindowHandle, Win32.WM_CAP_DRIVER_GET_CAPS, Marshal.SizeOf(caps), ref caps);
                hasDlgVideoDisplay = caps.fHasDlgVideoDisplay != 0;
                hasDlgVideoFormat = caps.fHasDlgVideoFormat != 0;
                hasDlgVideoSource = caps.fHasDlgVideoSource != 0;

                // TODO: Uncomment this to test which video formats are available -- remove this when finished testing
                //ShowVideoFormatDialog();

                // TODO: Get a list of supported video formats and throw an exception if none of them are supported

                // Set desired video format
                var format = VideoFormat;
                format.biCompression = 0;
                format.biBitCount = 24;
                VideoFormat = format;

                // Set callbacks
                frameCallback = FrameCallbackProc;
                if (Win32.SendMessage(camWindowHandle, Win32.WM_CAP_SET_CALLBACK_FRAME, 0, frameCallback) == 0)
                    throw new CamException("Could not set internal device callback.");

                success = true;
            }
            finally
            {
                if (!success)
                    Dispose();
            }
        }