Example #1
0
        public void InitializeCameraListDevice(int iDeviceNum, PictureBox box)
        {
            lock (thisLock)
            {
                if (IsDebugMode)
                {
                    Trace.WriteLine("Init No." + iDeviceNum + " Camara : " + CameraList[iDeviceNum] + " by Thread " + Thread.CurrentThread.ManagedThreadId + " on " + System.DateTime.Now);
                }

                groupBoxTestButton.Enabled = false;
                try
                {
                    if (mHotTabCamera != null)
                    {
                        mHotTabCamera.Dispose();
                        mHotTabCamera = null;
                    }

                    this.Invoke((MethodInvoker) delegate()
                    {
                        if (IsDebugMode)
                        {
                            Trace.WriteLine("New HotTabCamera No." + iDeviceNum + " by Thread " + Thread.CurrentThread.ManagedThreadId + " on " + System.DateTime.Now);
                        }
                        mHotTabCamera = new HotTabCamera(iDeviceNum, VIDEOWIDTH, VIDEOHEIGHT, VIDEOBITSPERPIXEL, box);
                    });

                    CameraResolution = HotTabCamera.CheckMaxResolution(iDeviceNum);
                    // 2M Camera : X = 1600, Y = 1200
                    // 5M Camera : X = 2592, Y = 1944
                    // 6M Camera : X = 3264, Y = 1836
                    if (IsDebugMode)
                    {
                        Trace.WriteLine("CameraResolution, X : " + CameraResolution.X + " , Y : " + CameraResolution.Y);
                    }

                    // 1. 只有單個相機, 沒有閃光燈
                    // 2. 有前後相機, 後相機有閃光燈
                    // 像素不到500萬, 一定是前鏡頭
                    if ((CameraResolution.X < 1920) && (CameraResolution.Y < 1440))
                    {
                        labelTestCameraName.Text = "Front Camera";
                        buttonFlash.Visible      = false;
                        buttonFlash.Enabled      = false;
                        buttonCapture.Enabled    = true;
                    }
                    else // ID82, IB10X, DAP7, M9020B, ID8HH, ID90 只有單一相機, 有閃光燈
                    {
                        labelTestCameraName.Text = "Rear Camera";
                        buttonFlash.Visible      = true;
                        buttonFlash.Enabled      = true;
                        buttonCapture.Enabled    = false;

                        mHotTabCamera.Flash(0);
                        if (Is8MCameraUsed)
                        {
                            Flash_8M(0);
                        }
                        else
                        {
                            SetFlashOff();
                        }
                    }

                    if (IsAutoModeCamera)
                    {
                        buttonFlash.Visible         = true;
                        buttonFlash.Enabled         = false;
                        buttonCapture.Visible       = true;
                        buttonCapture.Enabled       = false;
                        TimerCamaraCapture.Interval = TimerIntervalCamaraCapture;
                        TimerCamaraCapture.Start();
                    }
                }
                catch (Exception ex)
                {
                    ExceptionEvent(ex);
                }
                groupBoxTestButton.Enabled = true;
            }
        }