예제 #1
0
        /// <summary>
        /// Starts the camera and capture process
        /// </summary>
        public void Start()
        {
            if (_photoCamera == null)
            {
                InitializeCamera();
            }

            // At this point if application exits etc. without proper stopping of camera
            // it will throw an Exception.
            try
            {
                // Invokes these method calls on the UI-thread
                uiDispatcher.BeginInvoke(() =>
                {
                    _timer          = new DispatcherTimer();
                    _timer.Interval = _scanInterval;
                    _timer.Tick    += (o, arg) => ScanPreviewBuffer();

                    CameraButtons.ShutterKeyHalfPressed += (o, arg) =>
                    {
                        _photoCamera.Focus();
                    };

                    _timer.Start();
                });
            }
            catch (Exception)
            {
                // Do nothing
            }

            _photoCamera.Focus();
        }
예제 #2
0
 // Provide auto-focus in the viewfinder.
 private void focus_Clicked(object sender, System.Windows.RoutedEventArgs e)
 {
     if (cam.IsFocusSupported == true)
     {
         //Focus when a capture is not in progress.
         try
         {
             cam.Focus();
         }
         catch (Exception focusError)
         {
             // Cannot focus when a capture is in progress.
             this.Dispatcher.BeginInvoke(delegate()
             {
                 txtDebug.Text = focusError.Message;
             });
         }
     }
     else
     {
         // Write message to UI.
         this.Dispatcher.BeginInvoke(delegate()
         {
             txtDebug.Text = "Camera does not support programmable auto focus.";
         });
     }
 }
예제 #3
0
        /// <summary>
        /// Starts the camera and capture process
        /// </summary>
        public void Start()
        {
            if (_photoCamera == null)
            {
                InitializeCamera();
            }

            // At this point if application exits etc. without proper stopping of camera
            // it will throw an Exception.
            try
            {
                if (ScanOnAutoFocus)
                {
                    // Fired when Auto-Focus has completed =>
                    // start scanning the preview for codes
                    // and run a focus again (for
                    _photoCamera.AutoFocusCompleted += (o, arg) =>
                    {
                        if (doCancel)
                        {
                            return;
                        }

                        uiDispatcher.BeginInvoke(ScanPreviewBuffer);

                        if (_photoCamera != null)
                        {
                            _photoCamera.Focus();
                        }
                    };

                    _photoCamera.Focus();
                }
                else
                {
                    // Invokes these method calls on the UI-thread
                    uiDispatcher.BeginInvoke(() =>
                    {
                        _timer          = new DispatcherTimer();
                        _timer.Interval = _scanInterval;
                        _timer.Tick    += (o, arg) => ScanPreviewBuffer();

                        CameraButtons.ShutterKeyHalfPressed += (o, arg) =>
                        {
                            _photoCamera.Focus();
                        };

                        _timer.Start();
                    });
                }
            }
            catch (Exception)
            {
                // Do nothing
            }
        }
예제 #4
0
        void cam_Initialized(object sender, CameraOperationCompletedEventArgs e)
        {
            Dictionary <object, object> zxingHints
                = new Dictionary <object, object>()
                {
                { DecodeHintType.TRY_HARDER, true }
                };

            _cam.FlashMode = FlashMode.Auto;
            _reader        = new MultiFormatUPCEANReader(zxingHints);

            _cam.Focus();
        }
        void cam_Initialized(object sender, CameraOperationCompletedEventArgs e)
        {
            int width  = Convert.ToInt32(_photoCamera.PreviewResolution.Width);
            int height = Convert.ToInt32(_photoCamera.PreviewResolution.Height);

            _luminance = new PhotoCameraLuminanceSource(width, height);

            Dispatcher.BeginInvoke(() =>
            {
                _previewTransform.Rotation = _photoCamera.Orientation;
                _timer.Start();
            });
            _photoCamera.FlashMode = FlashMode.Auto;
            _photoCamera.Focus();
        }
예제 #6
0
        private void CameraButton_Click(object sender, RoutedEventArgs e)
        {
            if (photoCamera == null)
            {
                photoCamera              = new PhotoCamera();
                photoCamera.Initialized += OnPhotoCameraInitialized;
                previewVideo.SetSource(photoCamera);

                CameraButtons.ShutterKeyHalfPressed += (o, arg) => photoCamera.Focus();
            }

            if (timer == null)
            {
                timer = new DispatcherTimer {
                    Interval = TimeSpan.FromMilliseconds(500)
                };
                if (photoCamera.IsFocusSupported)
                {
                    photoCamera.AutoFocusCompleted += (o, arg) => { if (arg.Succeeded)
                                                                    {
                                                                        ScanPreviewBuffer();
                                                                    }
                    };
                    timer.Tick += (o, arg) => { try { photoCamera.Focus(); } catch (Exception) { } };
                }
                else
                {
                    timer.Tick += (o, arg) => ScanPreviewBuffer();
                }
            }

            BarcodeImage.Visibility = System.Windows.Visibility.Collapsed;
            previewRect.Visibility  = System.Windows.Visibility.Visible;
            timer.Start();
        }
예제 #7
0
 private void FocusingCamera(object sender, EventArgs eventArgs)
 {
     if (_cam.IsFocusSupported)
     {
         _cam.Focus();
     }
 }
예제 #8
0
 void CameraButtons_ShutterKeyHalfPressed(object sender, EventArgs e)
 {
     if (_phoneCamera != null)
     {
         _phoneCamera.Focus();
     }
 }
예제 #9
0
 private void PreviewRect_Tap(object sender, System.Windows.Input.GestureEventArgs e)
 {
     if (_isInitialized)
     {
         _photoCamera.Focus();
     }
 }
예제 #10
0
        private void Scan()
        {
            if (IsScanning && _initialized && _photoCamera != null && _luminanceSource != null && _reader != null)
            {
                try
                {
                    // 2-2-2012 - Rowdy.nl
                    // Focus the camera for better recognition of QR code's

                    if (_photoCamera.IsFocusSupported)
                    {
                        _photoCamera.Focus();
                    }
                    // End Rowdy.nl

                    _photoCamera.GetPreviewBufferY(_luminanceSource.PreviewBufferY);
                    var binarizer    = new HybridBinarizer(_luminanceSource);
                    var binaryBitmap = new BinaryBitmap(binarizer);
                    var result       = _reader.decode(binaryBitmap, QRCodeHint);

                    if (result != null)
                    {
                        StopScanning();
                        OnResult(result);
                    }
                }
                catch (ReaderException)
                {
                }
                catch (Exception ex)
                {
                    OnError(ex);
                }
            }
        }
예제 #11
0
 void PhotoCameraButtonHalfPress(object sender, EventArgs e)
 {
     if (isInitialized)
     {
         photoCamera.Focus();
     }
 }
예제 #12
0
        private void Scan()
        {
            if (IsScanning && _initialized && _photoCamera != null && _luminanceSource != null && _reader != null)
            {
                try
                {
                    // 2-2-2012 - Rowdy.nl
                    // Focus the camera for better recognition of QR code's
                    if (_photoCamera.IsFocusSupported)
                    {
                        _photoCamera.Focus();
                    }
                    // End Rowdy.nl

                    _photoCamera.GetPreviewBufferY(_luminanceSource.PreviewBufferY);
                    var binarizer    = new HybridBinarizer(_luminanceSource);
                    var binaryBitmap = new BinaryBitmap(binarizer);
                    var result       = _reader.decode(binaryBitmap, QRCodeHint);

                    StopScanning();
                    OnResult(result);
                }
                catch (ReaderException)
                {
                    // There was not a successful QR code read in the scan
                    // pass. Invoke and try again soon.
                    Dispatcher.BeginInvoke(Scan);
                }
                catch (Exception ex)
                {
                    OnError(ex);
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Al estar visible la vista, se inicializará la cámara
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            photoCamera              = new PhotoCamera();
            photoCamera.Initialized += OnPhotoCameraInitialized;
            previewVideo.SetSource(photoCamera);
            CameraButtons.ShutterKeyHalfPressed += (o, arg) => photoCamera.Focus();

            base.OnNavigatedTo(e);
        }
예제 #14
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            photoCamera = new PhotoCamera();
            previewVideo.SetSource(photoCamera);
            photoCamera.Initialized += OnPhotoCameraInitialized;

            CameraButtons.ShutterKeyHalfPressed += (o, arg) => photoCamera.Focus();

            base.OnNavigatedTo(e);
        }
예제 #15
0
        //カメラのプレビュー画面がタップされたら呼び出される
        private void PreviewRectangle_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (camera == null)
            {
                return;
            }

            camera.AutoFocusCompleted += new EventHandler <CameraOperationCompletedEventArgs>(camera_AutoFocusCompleted); //オートフォーカスが完了したら呼び出されるイベントハンドラを登録。
            camera.Focus();                                                                                               //オートフォーカス開始。
        }
예제 #16
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _photoCamera              = new PhotoCamera();
            _photoCamera.Initialized += OnPhotoCameraInitialized;
            _previewVideo.SetSource(_photoCamera); // _previewVideo is a VideoBrush-object

            CameraButtons.ShutterKeyHalfPressed += (o, arg) => _photoCamera.Focus();

            base.OnNavigatedTo(e);
        }
예제 #17
0
파일: Scanner.xaml.cs 프로젝트: BlaiseV/OFF
        // opening
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

             _photoCamera = new PhotoCamera();
             _photoCamera.Initialized += OnPhotoCameraInitialized;
             _previewVideo.SetSource(_photoCamera);

             CameraButtons.ShutterKeyHalfPressed += (o, arg) => _photoCamera.Focus();
        }
예제 #18
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _photoCamera = new PhotoCamera();
            _photoCamera.Initialized += OnPhotoCameraInitialized;
            _previewVideo.SetSource(_photoCamera); // _previewVideo is a VideoBrush-object

            CameraButtons.ShutterKeyHalfPressed += (o, arg) => _photoCamera.Focus();

            base.OnNavigatedTo(e);
        }
예제 #19
0
        // opening
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _photoCamera              = new PhotoCamera();
            _photoCamera.Initialized += OnPhotoCameraInitialized;
            _previewVideo.SetSource(_photoCamera);

            CameraButtons.ShutterKeyHalfPressed += (o, arg) => _photoCamera.Focus();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _photoCamera = new PhotoCamera();
            _photoCamera.Initialized += OnPhotoCameraInitialized;
            qrPreviewVideo.SetSource(_photoCamera);

            CameraButtons.ShutterKeyHalfPressed += (o, arg) => _photoCamera.Focus();
            if (server.name != null)
                joinMeeting();
            base.OnNavigatedTo(e);
        }
예제 #21
0
 public void Focus()
 {
     try
     {
         if (_photoCamera.IsFocusSupported)
         {
             _photoCamera.Focus();
         }
     }
     catch { }
 }
예제 #22
0
        //// Activate a flash mode.
        //// Cycle through flash mode options when the flash button is pressed.
        //private void changeFlash_Clicked(object sender, RoutedEventArgs e)
        //{

        //    switch (cam.FlashMode)
        //    {
        //        case FlashMode.Off:
        //            if (cam.IsFlashModeSupported(FlashMode.On))
        //            {
        //                // Specify that flash should be used.
        //                cam.FlashMode = FlashMode.On;
        //                FlashButton.Content = "Fl:On";
        //                currentFlashMode = "Flash mode: On";
        //            }
        //            break;
        //        case FlashMode.On:
        //            if (cam.IsFlashModeSupported(FlashMode.RedEyeReduction))
        //            {
        //                // Specify that the red-eye reduction flash should be used.
        //                cam.FlashMode = FlashMode.RedEyeReduction;
        //                FlashButton.Content = "Fl:RER";
        //                currentFlashMode = "Flash mode: RedEyeReduction";
        //            }
        //            else if (cam.IsFlashModeSupported(FlashMode.Auto))
        //            {
        //                // If red-eye reduction is not supported, specify automatic mode.
        //                cam.FlashMode = FlashMode.Auto;
        //                FlashButton.Content = "Fl:Auto";
        //                currentFlashMode = "Flash mode: Auto";
        //            }
        //            else
        //            {
        //                // If automatic is not supported, specify that no flash should be used.
        //                cam.FlashMode = FlashMode.Off;
        //                FlashButton.Content = "Fl:Off";
        //                currentFlashMode = "Flash mode: Off";
        //            }
        //            break;
        //        case FlashMode.RedEyeReduction:
        //            if (cam.IsFlashModeSupported(FlashMode.Auto))
        //            {
        //                // Specify that the flash should be used in the automatic mode.
        //                cam.FlashMode = FlashMode.Auto;
        //                FlashButton.Content = "Fl:Auto";
        //                currentFlashMode = "Flash mode: Auto";
        //            }
        //            else
        //            {
        //                // If automatic is not supported, specify that no flash should be used.
        //                cam.FlashMode = FlashMode.Off;
        //                FlashButton.Content = "Fl:Off";
        //                currentFlashMode = "Flash mode: Off";
        //            }
        //            break;
        //        case FlashMode.Auto:
        //            if (cam.IsFlashModeSupported(FlashMode.Off))
        //            {
        //                // Specify that no flash should be used.
        //                cam.FlashMode = FlashMode.Off;
        //                FlashButton.Content = "Fl:Off";
        //                currentFlashMode = "Flash mode: Off";
        //            }
        //            break;
        //    }

        //    // Display current flash mode.
        //    this.Dispatcher.BeginInvoke(delegate()
        //    {
        //        txtDebug.Text = currentFlashMode;
        //    });
        //}

        // Provide auto-focus in the viewfinder.
        private void focus_Clicked(object sender, System.Windows.RoutedEventArgs e)
        {
            if (cam.IsFocusSupported == true)
            {
                //Focus when a capture is not in progress.
                try
                {
                    cam.Focus();
                }
                catch (Exception ex) { LittleWatson.ReportException(ex); }
            }
        }
예제 #23
0
 private void OnButtonHalfPress(object sender, EventArgs e)
 {
     if (_photoCamera != null && _photoCamera.IsFocusSupported)
     {
         try
         {
             _photoCamera.Focus();
         }
         catch
         {
         }
     }
 }
예제 #24
0
        private void ScanPreviewBuffer()
        {
            try
            {
                if (_luminance == null)
                {
                    return;
                }

                _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
                // use a dummy writeable bitmap because the luminance values are written directly to the luminance buffer
                var result = _reader.Decode(_dummyBitmap);

                if (result == null)
                {
                    Dispatcher.BeginInvoke(() => _photoCamera.Focus());
                }
            }
            catch
            {
            }
        }
예제 #25
0
 private void makeFocus()
 {
     if (_photoCamera != null && _photoCamera.IsFocusSupported)
     {
         try
         {
             _photoCamera.Focus();
         }
         catch
         {
         }
     }
 }
예제 #26
0
        protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            if (_photoCamera != null)
            {
                // nama 3 ovat omia lisayksia
                _previewVideo = null;
                CameraButtons.ShutterKeyHalfPressed -= (o, arg) => _photoCamera.Focus();
                _timer.Tick -= (o, arg) => ScanPreviewBuffer();

                _photoCamera.Initialized -= OnPhotoCameraInitialized;
                _photoCamera.Dispose();
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _photoCamera              = new PhotoCamera();
            _photoCamera.Initialized += OnPhotoCameraInitialized;
            qrPreviewVideo.SetSource(_photoCamera);

            CameraButtons.ShutterKeyHalfPressed += (o, arg) => _photoCamera.Focus();
            if (server.name != null)
            {
                joinMeeting();
            }
            base.OnNavigatedTo(e);
        }
예제 #28
0
        private void m_btnFocus_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                cam.Focus();
                m_sFnDtNext = "";

                BtnBk.Fill = new SolidColorBrush(Colors.Green);
            }
            catch (Exception)
            {
                BtnBk.Fill = new SolidColorBrush(Colors.Red);
            }
        }
예제 #29
0
 private void _focusButton_Click(object sender, RoutedEventArgs e)
 {
     if (_photoCamera != null && _photoCamera.IsFocusSupported)
     {
         try
         {
             _photoCamera.CancelFocus();
             _photoCamera.Focus();
         }
         catch
         {
         }
     }
 }
예제 #30
0
 void ScannerControl_Tap(object sender, System.Windows.Input.GestureEventArgs e)
 {
     if (_currentCamera != null)
     {
         try
         {
             if (_currentCamera.IsFocusAtPointSupported)
             {
                 var    pt = e.GetPosition(this);
                 double x  = pt.X / this.ActualWidth;
                 double y  = pt.Y / this.ActualHeight;
                 _currentCamera.FocusAtPoint(x, y);
             }
             else if (_currentCamera.IsFocusSupported)
             {
                 _currentCamera.Focus();
             }
         }
         catch (Exception)
         {
             //for many reason focus may fail son we catch the error quietly
         }
     }
 }
예제 #31
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            _cam = new PhotoCamera();
              previewCanvas.SetSource(_cam);
              previewCanvas.RelativeTransform = new CompositeTransform() {CenterX = 0.5, CenterY = 0.5, Rotation = 90};

              _cam.CaptureImageAvailable += (sender, args) => {
              //var library = new MediaLibrary();
              string fileName = "wp8_kochbuch_" + _imgCounter + ".jpg";
              _library.SavePictureToCameraRoll(fileName, args.ImageStream);
            };

              _cam.CaptureCompleted += (sender, args) => { _imgCounter++; };

              CameraButtons.ShutterKeyPressed += (sender, args) => _cam.CaptureImage();
              CameraButtons.ShutterKeyHalfPressed += (sender, args) => _cam.Focus();
              //CameraButtons.ShutterKeyReleased += (sender, args) => { };

              base.OnNavigatedTo(e);
        }
예제 #32
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            _photoCamera = new PhotoCamera();
            _photoCamera.Initialized += OnPhotoCameraInitialized;
            _previewVideo.SetSource(_photoCamera);
            CameraButtons.ShutterKeyHalfPressed += (sender, args) => _photoCamera.Focus();

            _photoChooserTask = new PhotoChooserTask();
            _photoChooserTask.Completed += photoChooserTask_Completed;
            _photoChooserTask.Show();

            _timer = new DispatcherTimer
                         {
                             Interval = TimeSpan.FromMilliseconds(250)
                         };

            _timer.Tick += (o, arg) => ScanPreviewBuffer();
        }
예제 #33
0
        private void InitializePhoneCamera()
        {
            _phoneCamera              = new PhotoCamera(CameraType.Primary);
            _phoneCamera.Initialized += CameraInitialized;

            viewfinderBrush.SetSource(_phoneCamera);


            double cameraAspectRatioRotated = _phoneCamera.Resolution.Height / _phoneCamera.Resolution.Width;
            double deviceAspectRatio        = Application.Current.Host.Content.ActualHeight / Application.Current.Host.Content.ActualWidth;
            double scaleY = cameraAspectRatioRotated * deviceAspectRatio;


            viewfinderTransform.ScaleY = scaleY;

            CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;

            _phoneCamera.AutoFocusCompleted += _phoneCamera_AutoFocusCompleted;

            //Display the camera feed in the UI

            _autofocusTimer          = new DispatcherTimer();
            _autofocusTimer.Interval = TimeSpan.FromMilliseconds(2000);
            _autofocusTimer.Tick    += (o, arg) =>
            {
                if (_phoneCamera == null)
                {
                    return;
                }
                _phoneCamera.Focus();
            };

            // This timer will be used to scan the camera buffer every 250ms and scan for any barcodes
            _scanTimer          = new DispatcherTimer();
            _scanTimer.Interval = TimeSpan.FromMilliseconds(250);
            _scanTimer.Tick    += (o, arg) => ScanForBarcode();
        }
예제 #34
0
        private void callback(object sender, EventArgs e)
        {
            cam.FocusAtPoint(r, r);
            r = 1 - r;
            cam.Focus();
            textBlock1 = Globals.textBlock2;
            //if (Globals.tickCount % 50 == 0)
            //{
            //    System.Diagnostics.Debug.WriteLine(st.ElapsedMilliseconds/50);
            //    st.Reset();
            //    st.Start();
            //}

            PhotoCamera phCam = (PhotoCamera)cam;

            for (int i = Globals.n1 - 1; i > 0; i--)
            {
                Globals.x1[i] = Globals.x1[i - 1];
            }

            //pauseFramesEvent.WaitOne();
            phCam.GetPreviewBufferArgb32(ARGBPx);
            int tempVal = 0;

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    tempVal += (ARGBPx[j * (int)rect1.Width + i] >> 16) & 0xFF;
                }
            }
            //  tempVal+= (ARGBPx[(int)rect1.Width*(((int)rect1.Height+1)/2 - 50+i)]>>16)&0xFF;
            tempVal        /= 25;
            Globals.x1[0]   = tempVal;
            textBlock1.Text = Globals.x1[0] + "";
            Globals.lpf();
        }
예제 #35
0
 /// <summary>
 /// Starts a camera auto focus operation.
 /// </summary>
 /// <remarks>
 /// This method is already protected and only called when the service is currently running.
 /// </remarks>
 protected override void FocusCamera()
 {
     _photoCamera.Focus();
 }
        private async void ScanPreviewBuffer()
        {
            if (cameraAvailable_)
            {
                int[]     ARGBPx = new int[(int)cameraRes_.Width * (int)cameraRes_.Height];
                MailModel mail   = new MailModel();

                // Get the current frame
                camera_.Focus();
                camera_.GetPreviewBufferArgb32(ARGBPx);

                if (firstImageToCompare_ == null)
                {
                    firstImageToCompare_ =
                        new Image(ARGBPx, (int)cameraRes_.Width, (int)cameraRes_.Height);
                }
                // Do the comparison and detect the motion
                else
                {
                    Image newImage =
                        new Image(ARGBPx, (int)cameraRes_.Width, (int)cameraRes_.Height);
                    int[] r1 = firstImageToCompare_.GetR();
                    int[] r2 = newImage.GetR();

                    // Update the screen if any motion has been detected
                    if (DetectMotion(firstImageToCompare_, newImage))
                    {
                        textBlock.Visibility = Visibility.Visible;

                        // Encode the preview buffer as string
                        using (MemoryStream ms = new MemoryStream())
                        {
                            WriteableBitmap wbmp = new WriteableBitmap(
                                (int)cameraRes_.Width, (int)cameraRes_.Height);
                            ARGBPx.CopyTo(wbmp.Pixels, 0);
                            wbmp.SaveJpeg(ms,
                                          (int)cameraRes_.Width, (int)cameraRes_.Height, 0, 50);

                            mail.Image   = Convert.ToBase64String(ms.ToArray());
                            mail.Subject = "MSS";
                            mail.Body    = "Intruder detected!";
                            mail.To      = App.RoamingSettings.Values["Email"].ToString();
                        }

                        // Send e-mail
                        if (App.RoamingSettings.Values["Emailactivate"].Equals(true) && mailAvailable_)
                        {
                            mailAvailable_ = false;

                            if (!await Controllers.MailController.SendMail(mail))
                            {
                                MessageBox.Show("Email could not be sent!");
                            }
                        }
                    }
                    else
                    {
                        textBlock.Visibility = Visibility.Collapsed;
                    }

                    // Update the image
                    firstImageToCompare_ = newImage;
                }
            }
        }
        private void InitializePhoneCamera()
        {
            _phoneCamera = new PhotoCamera(CameraType.Primary);
            _phoneCamera.Initialized += CameraInitialized;

            viewfinderBrush.SetSource(_phoneCamera);

            double cameraAspectRatioRotated = _phoneCamera.Resolution.Height / _phoneCamera.Resolution.Width;
            double deviceAspectRatio = Application.Current.Host.Content.ActualHeight / Application.Current.Host.Content.ActualWidth;
            double scaleY = cameraAspectRatioRotated * deviceAspectRatio;

            viewfinderTransform.ScaleY = scaleY;

            CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;

            _phoneCamera.AutoFocusCompleted += _phoneCamera_AutoFocusCompleted;

            //Display the camera feed in the UI

            _autofocusTimer = new DispatcherTimer();
            _autofocusTimer.Interval = TimeSpan.FromMilliseconds(2000);
            _autofocusTimer.Tick += (o, arg) =>
            {
                if (_phoneCamera == null)
                {
                    return;
                }
                _phoneCamera.Focus();
            };

            // This timer will be used to scan the camera buffer every 250ms and scan for any barcodes
            _scanTimer = new DispatcherTimer();
            _scanTimer.Interval = TimeSpan.FromMilliseconds(250);
            _scanTimer.Tick += (o, arg) => ScanForBarcode();
        }
예제 #38
0
      private void CameraButton_Click(object sender, RoutedEventArgs e)
      {
         if (photoCamera == null)
         {
            photoCamera = new PhotoCamera();
            photoCamera.Initialized += OnPhotoCameraInitialized;
            previewVideo.SetSource(photoCamera);

            CameraButtons.ShutterKeyHalfPressed += (o, arg) => photoCamera.Focus();
         }

         if (timer == null)
         {
            timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) };
            timer.Tick += (o, arg) => ScanPreviewBuffer();
         }

         BarcodeImage.Visibility = System.Windows.Visibility.Collapsed;
         previewRect.Visibility = System.Windows.Visibility.Visible;
         timer.Start();
      }
예제 #39
0
        void Scan_Loaded(object sender, RoutedEventArgs e)
        {
            if (photoCamera == null)
            {
                photoCamera = new PhotoCamera();
                photoCamera.Initialized += OnPhotoCameraInitialized;
                previewVideo.SetSource(photoCamera);

                CameraButtons.ShutterKeyHalfPressed += (o, arg) => photoCamera.Focus();
            }

            if (timer == null)
            {
                timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) };
                if (photoCamera.IsFocusSupported)
                {
                    photoCamera.AutoFocusCompleted += (o, arg) => { if (arg.Succeeded) ScanPreviewBuffer(); };
                    timer.Tick += (o, arg) => { try { photoCamera.Focus(); } catch (Exception) { } };
                }
                else
                {
                    timer.Tick += (o, arg) => ScanPreviewBuffer();
                }
            }

            previewRect.Visibility = System.Windows.Visibility.Visible;
            timer.Start();
        }