Example #1
0
        //private Size GetPreviewWindowRealSize()
        //{
        //    tDSImageSize tmpsize = new tDSImageSize();
        //    int m_iRelsel = 0;
        //    int nWidth = 640, nHeight = 480;
        //    tDSCameraCapability dscapability = new tDSCameraCapability();
        //    XCamera.CameraGetCapability(1, ref dscapability);
        //    if (XCamera.CameraGetImageSizeSel(1, ref m_iRelsel, false) == emDSCameraStatus.STATUS_OK)
        //    {
        //        Byte[] arrtmp = new Byte[4];
        //        XCamera.CopyMemory(Marshal.UnsafeAddrOfPinnedArrayElement(arrtmp, 0), dscapability.pImageSizeDesc + m_iRelsel * Marshal.SizeOf(tmpsize) + 52, 4);
        //        nWidth = BitConverter.ToInt32(arrtmp, 0);
        //        XCamera.CopyMemory(Marshal.UnsafeAddrOfPinnedArrayElement(arrtmp, 0), dscapability.pImageSizeDesc + m_iRelsel * Marshal.SizeOf(tmpsize) + 56, 4);
        //        nHeight = BitConverter.ToInt32(arrtmp, 0);
        //    }
        //    return new Size(nWidth, nHeight);
        //}
        #endregion

        //private void UpdateDisplayWindow()
        //{
        //    tDSImageSize tmpsize = new tDSImageSize();
        //    int m_iRelsel = 0;
        //    int nWidth = 640, nHeight = 480;
        //    tDSCameraCapability dscapability = new tDSCameraCapability();
        //    XCamera.CameraGetCapability(1, ref dscapability);
        //    if (XCamera.CameraGetImageSizeSel(1, ref m_iRelsel, false) == emDSCameraStatus.STATUS_OK)
        //    {
        //        Byte[] arrtmp = new Byte[4];
        //        XCamera.CopyMemory(Marshal.UnsafeAddrOfPinnedArrayElement(arrtmp, 0), dscapability.pImageSizeDesc + m_iRelsel * Marshal.SizeOf(tmpsize) + 52, 4);
        //        nWidth = BitConverter.ToInt32(arrtmp, 0);
        //        XCamera.CopyMemory(Marshal.UnsafeAddrOfPinnedArrayElement(arrtmp, 0), dscapability.pImageSizeDesc + m_iRelsel * Marshal.SizeOf(tmpsize) + 56, 4);
        //        nHeight = BitConverter.ToInt32(arrtmp, 0);
        //    }

        //    pictureBox.Width = nWidth;
        //    //pictureBox.Height = nHeight - 40;
        //    pictureBox.Height = nHeight;
        //    pictureBox.Left = 0;
        //    //pictureBox.Top = 24;
        //    pictureBox.Top = 0;
        //    //---------------------------------------------------------------------------------------------------------------------------------------
        //    XCamera.CameraSetDisplaySize(1, pictureBox.Width, pictureBox.Height);
        //}

        private void PreviewForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (!IsCloseWithMainForm)
                {
                    XCamera cam = XCamera.GetInstance();
                    bool    isSuccessToStopCam = false;
                    if (cam.IsActive())
                    {
                        if (cam.RunMode != emDSRunMode.RUNMODE_STOP)
                        {
                            isSuccessToStopCam = cam.Stop();
                            System.Threading.Thread.Sleep(100);
                        }
                        if (isSuccessToStopCam && cam.UnInit())
                        {
                            System.Threading.Thread.Sleep(100);
                            OnCameraClosed(new EventArgs());
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                _logger.Error(ex.Message);
            }
        }
Example #2
0
        /// <summary>
        /// 开始预览视频(同时只能打开一个相机)
        /// </summary>
        /// <param name="cameraName"></param>
        public bool StartPreview(string cameraName)
        {
            try
            {
                bool    retVal = false;
                XCamera cam    = XCamera.GetInstance();
                if (cam.IsActive())
                {
                    if (cam.RunMode != emDSRunMode.RUNMODE_STOP)
                    {
                        cam.Stop();
                    }
                    cam.UnInit();
                }
                _cameraCallbackProc = new XCamera.DelegateProc(SnapThreadCallback);

                //test

                if (cam.Init(_cameraCallbackProc, cameraName, _imageBox.Handle))
                //if (cam.Init(_cameraCallbackProc, cameraName, _imageBack.Handle))
                {
                    if (cam.Play())
                    {
                        retVal = true;
                        //this.RealSize();
                        this.FitScreen();
                        PublishCameraOpenedEvent(new EventArgs());
                    }
                }
                else
                {
                    retVal = false;
                }
                return(retVal);
            }
            catch (System.Exception ex)
            {
                _logger.Error(ex.Message);
                return(false);
            }
        }