示例#1
0
        /// <summary>
        /// 开启视频,,已经打开则关闭重新开启
        /// </summary>
        /// <param name="channel">视频通道号</param>
        /// <param name="hdlpreview">预览控件句柄</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool StartChannel(int channel, Panel hdlpreview)
        {
            bool success = true;
            int  hdl     = channel;

            if (!this.channelHandle.ContainsKey(channel))
            {
                return(false);
            }
            switch (this.VideoType)
            {
            case VideoType.MvAPI:
                return(this.OpenChannel(this.channelHandle[channel], hdlpreview.Handle));

            case VideoType.Sa7134Capture:
                try
                {
                    success = Sa7134Capture.VCAStartVideoPreview(this.channelHandle[channel]);
                }
                catch (Exception ex)
                {
                    success = false;
                }
                break;
            }
            return(success);
        }
示例#2
0
        /// <summary>
        /// 打开视频通道,已经打开则关闭后重新打开
        /// </summary>
        /// <param name="channel">视频通道号</param>
        /// <param name="hdlpreview">预览控件句柄</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool OpenChannel(int channel, Panel hdlpreview)
        {
            bool success = true;
            int  hdl     = channel;

            if (this.channelHandle.ContainsKey(channel))
            {
                this.CloseChannel(channel);
            }
            switch (this.VideoType)
            {
            case VideoType.MvAPI:
                try
                {
                    hdl = MvAPI.MV_OpenDevice((uint)channel, false);
                }
                catch (Exception ex)
                {
                    hdl = 0;
                }
                if (hdl < 1)
                {
                    return(false);
                }
                try
                {
                    success = MvAPI.MV_SetDeviceParameter(hdl, (int)MV_PARAMTER.DISP_WHND, (uint)hdlpreview.Handle);
                    success = success && MvAPI.MV_SetDeviceParameter(hdl, hdlpreview.Width, 336);
                    success = success && MvAPI.MV_SetDeviceParameter(hdl, hdlpreview.Height, 256);
                    success = success && 1 == MvAPI.MV_OperateDevice(hdl, (int)RUNOPER.MVRUN);
                }
                catch (Exception ex)
                {
                    success = false;
                }
                break;

            case VideoType.Sa7134Capture:
                try
                {
                    success = Sa7134Capture.VCAOpenDevice(channel, hdlpreview.Handle);
                    success = success && Sa7134Capture.VCAStartVideoPreview(channel);
                }
                catch (Exception ex)
                {
                    success = false;
                }
                break;
            }
            if (success)
            {
                this.channelHandle.Add(channel, hdl);
            }
            return(success);
        }