Example #1
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            // Check to see if the camera is available on the device.
            if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) ||
                (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) == true))
            {
                // Initialize the default camera.
                cam = new Microsoft.Devices.PhotoCamera();

                //Event is fired when the PhotoCamera object has been initialized
                cam.Initialized += new EventHandler <Microsoft.Devices.CameraOperationCompletedEventArgs>(cam_Initialized);

                //Set the VideoBrush source to the camera
                viewfinderBrush.SetSource(cam);

                //to rotate the camera (upright)
                viewfinderBrush.RelativeTransform = new CompositeTransform()
                {
                    CenterX = 0.5, CenterY = 0.5, Rotation = 90
                };
            }
            else
            {
                // The camera is not supported on the device.
            }
        }
        //TestSamples
        //GeoCoordinate position = new GeoCoordinate { Latitude = 19.11906242024381, Longitude = 72.85692904290141 };
        //GeoCoordinate point1 = new GeoCoordinate { Latitude = 19.12032323794295, Longitude = 72.85714849940776 };

        public MainPage()
        {
            InitializeComponent();
            camera = new PhotoCamera(CameraType.Primary);
            viewFinderBrush.SetSource(camera);

            augmentedReality = new AugmentedPlacemarks();

            camera = new PhotoCamera(CameraType.Primary);
            viewFinderBrush.SetSource(camera);
            userLocation            = new Pushpin();
            userLocation.Background = new SolidColorBrush(Colors.Blue);
            oldPoint = new GeoCoordinate();

            traceLine = new MapPolyline()
            {
                Foreground      = new SolidColorBrush(Colors.Red),
                StrokeThickness = 2,
                Locations       = new LocationCollection(),
                Opacity         = 1.0
            };

            //Debug.WriteLine(LatLongMath.GetDistance(position, point1));


            StartupCode();
        }
Example #3
0
        private void LoadCameraBrush()
        {
            if (_currentCamera != null)
            {
                return; //camera already initialized
            }
            //find the other camera if the prefered camera  is not available (usualy Primary Camera is always available)
            CameraType invertCameraType = _cameraType == CameraType.FrontFacing ? CameraType.Primary : CameraType.FrontFacing;
            CameraType targetType       = PhotoCamera.IsCameraTypeSupported(_cameraType)? _cameraType : invertCameraType;

            ReloadCamera -= ScannerControl_ReloadCamera;
            ReloadCamera += ScannerControl_ReloadCamera;

            //Create the photo camera only if supported
            if (PhotoCamera.IsCameraTypeSupported(targetType))
            {
                //Create the timer that will capture camera frame
                BuildTimer();

                //Create the camera object
                _currentCamera              = new PhotoCamera(targetType);
                _currentCamera.Initialized += _currentCamera_Initialized;
                _videoPreviewBrush.SetSource(_currentCamera);
                if (_rootVisual != null)
                {
                    ApplyOrientation(_rootVisual.Orientation);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the BarcodeScanningView class.
        /// </summary>
        public BarcodeScanningView()
        {
            InitializeComponent();

            _scannerWorker = new BackgroundWorker();
            _scannerWorker.DoWork += scannerWorker_DoWork;
            _scannerWorker.RunWorkerCompleted += scannerWorker_RunWorkerCompleted;

            Loaded += (sender, args) =>
                          {
                              if (_photoCamera == null)
                              {
                                  _photoCamera = new PhotoCamera();
                                  _photoCamera.Initialized += OnPhotoCameraInitialized;
                                  previewVideo.SetSource(_photoCamera);

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

                              if (_timer == null)
                              {
                                  _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) };
                                  _timer.Tick +=TimerOnTick;
                              }

                              if (_focusTimer == null)
                              {
                                  _focusTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(4500) };
                                  _focusTimer.Tick += (o, eventArgs) => FocusTheCamera();
                              }

                              _timer.Start();
                          };
        }
Example #5
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (UseCamera)
            {
                camera = new PhotoCamera(CameraType.Primary);
                CameraView.SetSource(camera);
            }
            if (UseAccelerometer)
            {
#pragma warning disable 612,618
                accelerometer.ReadingChanged += Accelerometer_ReadingChanged;
#pragma warning restore 612,618
                accelerometer.Start();
            }
            ReplayTimer.Tick += ReplayTimer_Tick;
            if (MediaPlayer.State == MediaState.Paused)
            {
                MediaPlayer.Resume();
            }

            if (ChatKeywords.Count == 0)
            {
                ChatKeywords = Keyword.LoadKeywordsFromFile("categories.txt");
            }
        }
Example #6
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // Delayed due to Camera init bug in WP71 SDK Beta 2
            // See http://forums.create.msdn.com/forums/p/85830/516843.aspx
            Dispatcher.BeginInvoke(() =>
            {
                // Initialize the webcam
                photoCamera                          = new PhotoCamera();
                photoCamera.Initialized             += PhotoCameraInitialized;
                CameraButtons.ShutterKeyHalfPressed += PhotoCameraButtonHalfPress;
                isInitialized                        = false;
                isDetecting                          = false;

                // Fill the Viewport Rectangle with the VideoBrush
                var vidBrush = new VideoBrush();
                vidBrush.SetSource(photoCamera);
                Viewport.Fill = vidBrush;

                // Start timer
                dispatcherTimer = new DispatcherTimer {
                    Interval = TimeSpan.FromMilliseconds(50)
                };
                dispatcherTimer.Tick += (sender, e1) => Detect();
                dispatcherTimer.Start();
            });
        }
Example #7
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            //Networking.DeleteFile("CurrentGame");
            //Networking.DeleteFile("Players");

            //Check if a game in progress has already been saved and continue it
            string data = Networking.LoadData("CurrentGame");
            if (data != "" && MessageBox.Show("Would you like to resume the game with id of " + data, "Continue Game", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                NavigationService.Navigate(new Uri("/GamePage.xaml?gameid=" + data, UriKind.Relative));
            else
            {
                _timer = new DispatcherTimer();
                _timer.Interval = TimeSpan.FromMilliseconds(250);
                _timer.Tick += (o, arg) => ScanPreviewBuffer();
                //The timer auto-starts so it needs to be stopped here
                _timer.Stop();
            }

            //Login to the server
            Networking.Login();

            _cam = new PhotoCamera();

            _cam.Initialized += cam_Initialized;

            video.Fill = _videoBrush;
            _videoBrush.SetSource(_cam);
            _videoBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 };
        }
 protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
 {
     camera.AutoFocusCompleted -= new EventHandler<CameraOperationCompletedEventArgs>(camera_AutoFocusCompleted);
     camera.CancelFocus();
     camera.Dispose();
     camera = null;
 }
Example #9
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();
        }
Example #10
0
        /**
         * Reinitializes the camera: creates a new one, and adds it as a source for the
         * video brush.
         */
        private void InitCamera()
        {
            mCamera.Dispose();
            mCamera = null;
            mCamera = new PhotoCamera(mCameraType);

            isCameraInitialized = false;

            AutoResetEvent are = new AutoResetEvent(false);

            mCamera.Initialized += new EventHandler <CameraOperationCompletedEventArgs>(
                delegate(object o, CameraOperationCompletedEventArgs args)
            {
                try
                {
                    mCamera.FlashMode   = mFlashMode;
                    isCameraInitialized = true;
                    are.Set();
                }
                catch { }
            });

            MoSync.Util.RunActionOnMainThreadSync(() =>
            {
                mVideoBrush.SetSource(mCamera);
            });
            // we need to wait until the camere is initialized before doing other operations
            // with it or getting/setting its properties
            are.WaitOne();
        }
Example #11
0
        //Code for initialization, capture completed, image availability events; also setting the source for the viewfinder.
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            capture.IsEnabled        = false;
            camHeightInput.IsEnabled = false;
            TargetDot2.Opacity       = 0;
            checkForActiveProducts();
            // Check to see if the camera is available on the phone.
            if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true && Motion.IsSupported == true)
            {
                // Initialize the camera, when available.
                camera = new Microsoft.Devices.PhotoCamera(CameraType.Primary);

                //Set the VideoBrush source to the camera.
                cameraViewBrush.SetSource(camera);
                cameraViewBrush.Stretch           = Stretch.UniformToFill;
                cameraView.Background             = cameraViewBrush;
                motionSensor                      = new Motion();
                motionSensor.TimeBetweenUpdates   = TimeSpan.FromMilliseconds(20);
                motionSensor.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <MotionReading> >(motionActor);
                motionSensor.Start();
                camHeightInput.IsEnabled = true;
                MessageBox.Show("Hello, welcome to Measure180! To use this app you must roughly know the height you are holding the phone (camHeight)," +
                                " you may use any unit. Hold the phone at your specified height and point the dot at the base of the object and hit capture," +
                                " that will give you the distance. If the object is not at ground level the distance will be off, you must subtract off the height at which it is off the ground from the camHeight" +
                                " and input that as the new camHeight. To measure height you must move the dot to the top of the of the object after capturing distance and hit capture again. IMPORTANT: YOU MUST NOT MOVE YOUR PHONE from the initial camHeight you set when you captured distance" +
                                " you have to angle the phone until the dot touches the top of the object or else the measurement will be off.\n\n" +
                                " TL;DR: point dot at bottom of object, capture, top of object, capture. If the measurement is horribly off, try reading the tutorial!");
                MessageBox.Show("Instructions were on the last page, don't blame me if you didn't read it and start complaining about bad measurements. This app is as accurate as the user is willing to be, thus a tripod is recommended for super accurate measurements.");
            }
            else
            {
                MessageBox.Show("Motion API and/or primary camera is not supported on this device. Application can not run!");
            }
        }
Example #12
0
 public void SetCamera()
 {
     _photoCamera = new PhotoCamera(CameraType.Primary);
     cameraViewFinder.SetSource(_photoCamera);
     double cameraRotation = _photoCamera.Orientation;
     previewTransform.Rotation = _photoCamera.Orientation + 0;
 }
Example #13
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (flashInitialized == false)
            {
                // Check to see if the camera is available on the device.
                if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
                {
                    // Use standard camera on back of device.
                    _videoCamera = new VideoCamera();

                    // Event is fired when the video camera object has been initialized.
                    _videoCamera.Initialized += VideoCamera_Initialized;

                    // Add the photo camera to the video source
                    _videoCameraVisualizer = new VideoCameraVisualizer();
                    _videoCameraVisualizer.SetSource(_videoCamera);
                }
                flashInitialized = true;
            }

            if (settings.Contains("myInfo"))
            {
                iceText.Text = settings["myInfo"].ToString();
            }
            else
            {
                settings.Add("myInfo", "IMPORTANT IN CASE OF EMERGENCY INFORMATION: PLEASE CHANGE");
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _isCameraInitialized = false;
            _isTrial = new IsTrialQuery().Get();

            if (_isTrial)
            {
                var menuItem = new ApplicationBarMenuItem("Buy full version");
                menuItem.Click += (sender, args) => Deployment.Current.Dispatcher.BeginInvoke(() => new MarketplaceDetailTask().Show());
                ApplicationBar.MenuItems.Add(menuItem);
            }

            OnOrientationChanged(this, new OrientationChangedEventArgs(Orientation));

            if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
            {
                _pixelator = new Pixelator(new PixelationSizeQuery().Get(), true);

                _photoCamera = new PhotoCamera(CameraType.Primary);
                _photoCamera.Initialized += OnCameraInitialized;
                _photoCamera.CaptureImageAvailable += OnCameraCaptureImageAvailable;
                _photoCamera.CaptureCompleted += OnCameraCaptureCompleted;
                _photoCamera.CaptureStarted += OnCameraCaptureStarted;

                ViewfinderBrush.SetSource(_photoCamera);
            }
            else
            {
                // TODO: handle possibility of no camera
            }
        }
Example #15
0
        BinaryBitmap GetBitmapFromVideo(PhotoCamera cam)
        {
            BinaryBitmap binaryBitmap = null;

            try
            {
                // Update buffer size
                var pixelWidth  = (int)_cam.PreviewResolution.Width;
                var pixelHeight = (int)_cam.PreviewResolution.Height;

                if (_buffer == null || _buffer.Length != (pixelWidth * pixelHeight))
                {
                    _buffer = new byte[pixelWidth * pixelHeight];
                }

                _cam.GetPreviewBufferY(_buffer);

                var luminance = new RGBLuminanceSource(_buffer, pixelWidth, pixelHeight, true);
                var binarizer = new com.google.zxing.common.HybridBinarizer(luminance);

                binaryBitmap = new BinaryBitmap(binarizer);
            }
            catch
            {
            }

            return(binaryBitmap);
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            Connecting.Text           = AppResources.searching;
            ProgressB.IsIndeterminate = false;
            Connecting.Visibility     = System.Windows.Visibility.Visible;

            //***************************sacar, solo para probar sin cel*************************************
            // timer interval specified as 1 second
            newTimer.Interval = TimeSpan.FromSeconds(2);
            // Sub-routine OnTimerTick will be called at every 1 second
            newTimer.Tick += OnTimerTick;
            // starting the timer
            //newTimer.Start();
            //*************************************************************************************



            // Initialize the camera object
            _phoneCamera              = new PhotoCamera();
            _phoneCamera.Initialized += cam_Initialized;

            CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;

            //Display the camera feed in the UI
            viewfinderBrush.SetSource(_phoneCamera);


            // 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();

            base.OnNavigatedTo(e);
        }
Example #17
0
        // frame pump
        void PumpFrames()
        {
            // Create capture buffer.
            byte[] YPx = new byte[(int)cam.PreviewResolution.Width * (int)cam.PreviewResolution.Height];

            try
            {
                PhotoCamera phCam = (PhotoCamera)cam;

                while (pumpFrames)
                {
                    pauseFramesEvent.WaitOne();

                    // Copies the current viewfinder frame into a buffer for further manipulation.
                    phCam.GetPreviewBufferY(YPx);

                    // DO STUFF HERE
                    m_d3dInterop.update(YPx, (int)cam.PreviewResolution.Width, (int)cam.PreviewResolution.Height);

                    pauseFramesEvent.Reset();
                }
            }
            catch (Exception e)
            {
                this.Dispatcher.BeginInvoke(delegate()
                {
                    // Display error message.
                    txtDebug.Text = e.Message;
                });
            }
        }
        private void InitScene()
        {
            if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) ||
                (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) == true))
            {
                if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing))
                {
                    cam = new PhotoCamera(CameraType.FrontFacing);
                }
                else
                {
                    cam = new PhotoCamera(CameraType.Primary);
                }

                _cameraHeight = cam.AvailableResolutions.FirstOrDefault().Height;
                _cameraWidth  = cam.AvailableResolutions.FirstOrDefault().Width;

                cam.CaptureImageAvailable += cam_CaptureImageAvailable;
                viewfinderBrush.SetSource(cam);
            }
            else
            {
                Dispatcher.BeginInvoke(() =>
                {
                    Message = "A Camera is not available on this device.";
                });
            }
        }
Example #19
0
        public BottleDetectionUseCases(CompositeDisposable disposables)
            : base(disposables)
        {
            photoCamera = new PhotoCamera();
            client      = new CustomVisionClient();

            CanTakePhoto = Observable.CombineLatest(photoCamera.CanTakePhoto, client.CanPost)
                           .Select(x => !x.Contains(false))
                           .ToReactiveProperty();

            PhotoCamera.ShootingPlan plan = null;
            byte[] imageData = null;
            photoCamera.OnPhotoCaptured
            .Do(b =>
            {
                plan      = photoCamera.Plan;
                imageData = b;
            })
            .SelectMany(x => client.Post(x))
            .Do(res =>
            {
                var positions = client.Convert(plan, imageData, res);
                var status    = new DetectedStatus
                {
                    Plan      = plan,
                    Positions = positions,
                };
                onBottleDetected.OnNext(status);
            })
            .Subscribe()
            .AddTo(disposables);
        }
        private void cam_Initialized(object sender, CameraOperationCompletedEventArgs e)
        {
            if (!e.Succeeded)
            {
                cam = null;
                return;
            }

            try
            {
                cam = (PhotoCamera)sender;
                cam.Resolution = cam.AvailableResolutions.First();
            }
            catch (Exception)
            {
                cam = null;
                return;
            }

            this.Dispatcher.BeginInvoke(delegate()
            {
                if (cam == null)
                    return;

                WriteableBitmap bitmap = new WriteableBitmap((int)cam.PreviewResolution.Width,
                                                             (int)cam.PreviewResolution.Height);
                frameStart = DateTime.Now;
                cam.GetPreviewBufferArgb32(bitmap.Pixels);
                detectFaces(bitmap);
            });
        }
Example #21
0
        public DeviceInfo()
        {
            this.Manufacturer    = DeviceStatus.DeviceManufacturer;
            this.Model           = DeviceStatus.DeviceName;
            this.OperatingSystem = Env.OSVersion.ToString();

            var deviceIdBytes = (byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId");

            this.DeviceId = Convert.ToBase64String(deviceIdBytes);

            this.IsRearCameraAvailable  = PhotoCamera.IsCameraTypeSupported(CameraType.Primary);
            this.IsFrontCameraAvailable = PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing);
            this.IsSimulator            = (DevEnv.DeviceType == DeviceType.Emulator);

            switch (GetScaleFactor())
            {
            case 150:
                this.ScreenWidth  = 720;
                this.ScreenHeight = 1280;
                break;

            case 160:
                this.ScreenWidth  = 768;
                this.ScreenHeight = 1280;
                break;

            case 100:
            default:
                this.ScreenWidth  = 480;
                this.ScreenHeight = 800;
                break;
            }
        }
Example #22
0
        //takes the video input and creates a bitmap of the image
        BinaryBitmap GetBitmapFromVideo(PhotoCamera cam)
        {
            BinaryBitmap binaryBitmap = null;

            try
            {
                // Update buffer size    
                var pixelWidth = (int)_cam.PreviewResolution.Width;
                var pixelHeight = (int)_cam.PreviewResolution.Height;

                if (_buffer == null || _buffer.Length != (pixelWidth * pixelHeight))
                {
                    _buffer = new byte[pixelWidth * pixelHeight];
                }

                _cam.GetPreviewBufferY(_buffer);

                var luminance = new RGBLuminanceSource(_buffer, pixelWidth, pixelHeight, true);
                var binarizer = new com.google.zxing.common.HybridBinarizer(luminance);

                binaryBitmap = new BinaryBitmap(binarizer);
            }
            catch
            {
            }

            return binaryBitmap;
        }
 public RawCamera()
 {
     InitializeComponent();
     photoCamera = new PhotoCamera();
     photoCamera.CaptureImageAvailable += new EventHandler <ContentReadyEventArgs>(photoCamera_CaptureImageAvailable);
     CameraSource.SetSource(photoCamera);
 }
 //Code for initialization, capture completed, image availability events; also setting the source for the viewfinder.
 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
 {
     // Check to see if the camera is available on the phone.
     if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) ||
          (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) == true))
     {
         // Initialize the camera, when available.
         if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
         {
             // Use front-facing camera if available.
             cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
         }
         else
         {
             // Otherwise, use standard camera on back of phone.
             cam = new Microsoft.Devices.PhotoCamera(CameraType.FrontFacing);
         }
         // Event is fired when the capture sequence is complete and an image is available.
         cam.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(cam_CaptureImageAvailable);
         //Set the VideoBrush source to the camera.
         viewfinderBrush.SetSource(cam);
         viewfinderBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 };
     }
     else
     {
         // The camera is not supported on the phone.
         this.Dispatcher.BeginInvoke(delegate()
         {
             // Write message.
             txtDebug.Text = "A Camera is not available on this phone.";
         });
         // Disable UI.
         ShutterButton.IsEnabled = false;
     }
 }
Example #25
0
        internal static Camera CreateCamera(OperationType operationType, StoreMediaOptions storeOptions)
        {
            if (Cameras.TryGetValue(operationType, out Camera camera))
            {
                return(camera);
            }

            switch (operationType)
            {
            case OperationType.Photo:
                camera = new PhotoCamera(storeOptions);
                Cameras[OperationType.Photo] = camera;
                break;

            case OperationType.Video:
                camera = new VideoCamera(storeOptions);
                Cameras[OperationType.Video] = camera;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(operationType), operationType, null);
            }

            return(camera);
        }
        /// <summary>
        /// Show the CodeScannerPopup and look for something scannable
        /// </summary>
        /// <param name="appTitle">Your app title</param>
        /// <param name="pageTitle">The page title</param>
        /// <returns>ScanResult or null (BackKeyPress/close())</returns>
        public async Task <ScanResult> ShowAsync(string appTitle, string pageTitle = "scan")
        {
            result = null;
            //set up ui
            ApplicationTitle.Text = appTitle;
            PageTitle.Text        = pageTitle;
            Camera              = new PhotoCamera(CameraType.Primary);//use the camera we were given
            Camera.Initialized += new EventHandler <CameraOperationCompletedEventArgs>(Camera_Initialized);
            previewVideo.SetSource(Camera);
            previewTransform.Rotation = 90;
            //initialize camera
            scanTask = new Task(new Action(delegate
            {
                while (!cancel)
                {
                    Scan();
                }
            }));//start scanning
            scanTask.Start();
            //show us
            this.IsOpen = true;
            //wait for the scan to complete
            await scanTask;

            Dispose();           //release resources and hide
            this.IsOpen = false; //hide
            return(result);
        }
Example #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BarcodeScannerUI"/> class.
        /// This implementation not use camera autofocus.
        /// </summary>
        public BarcodeScannerUI()
        {
            this.InitializeComponent();

            // Instantiate objects and start camera preview
            this.camera = new PhotoCamera();
            this.reader = new BarcodeReader {
                Options = { TryHarder = true }
            };
            this.CameraBrush.SetSource(this.camera);

            // Bind events
            this.camera.Initialized += this.CameraInitialized;
            this.reader.ResultFound += this.ReaderResultFound;

            this.timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(100)
            };
            this.timer.Tick += (sender, args) => ScanForBarcode();

            this.BackKeyPress += CancelScan;

            CameraButtons.ShutterKeyHalfPressed += StartCameraFocus;
            camera.AutoFocusCompleted           += StartCameraFocus;
        }
Example #28
0
        // Load data for the ViewModel Items
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }

            // Initialize the camera object
            _phoneCamera                     = new PhotoCamera();
            _phoneCamera.Initialized        += cam_Initialized;
            _phoneCamera.AutoFocusCompleted += _phoneCamera_AutoFocusCompleted;

            CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;

            //Display the camera feed in the UI
            viewfinderBrush.SetSource(_phoneCamera);


            // 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();

            viewfinderCanvas.Tap += new EventHandler <GestureEventArgs>(focus_Tapped);

            base.OnNavigatedTo(e);
        }
Example #29
0
        private void UninitializeCamera()
        {
            StopAutofocusTimer();
            StopScanning();

            if (_phoneCamera != null)
            {
                // Cleanup
                _phoneCamera.Initialized            -= CameraInitialized;
                CameraButtons.ShutterKeyHalfPressed -= CameraButtons_ShutterKeyHalfPressed;
                _phoneCamera.CancelFocus();
                _phoneCamera.Dispose();
                _phoneCamera = null;
            }

            if (_autofocusTimer != null)
            {
                _autofocusTimer = null;
            }

            if (_scanTimer != null)
            {
                _scanTimer = null;
            }

            if (_previewBuffer != null)
            {
                _previewBuffer = null;
            }

            if (_barcodeReader != null)
            {
                _barcodeReader = null;
            }
        }
Example #30
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Emulator)
            {
                MessageBox.Show("You must deploy this sample to a device, instead of the emulator so that you can get a video stream including a barcode/QR code");
                this.IsEnabled = false;
                base.NavigationService.GoBack();
            }
            else
            {
                string type = "";
                if (NavigationContext.QueryString.TryGetValue("type", out type) && type == "qrcode")
                {
                    _reader = new QRCodeReader();
                }
                else
                {
                    _reader = new EAN13Reader();
                }

                _photoCamera = new PhotoCamera();
                _photoCamera.Initialized += new EventHandler<CameraOperationCompletedEventArgs>(cam_Initialized);
                _videoBrush.SetSource(_photoCamera);
                BarCodeRectInitial();
                base.OnNavigatedTo(e);
            }
        }
Example #31
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

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

                CameraButtons.ShutterKeyHalfPressed += OnButtonHalfPress;
            }

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

            if (scanEffect == null)
            {
                var resourceStream = Application.GetResourceStream(new System.Uri("Plugins/com.phonegap.plugins.barcodescanner/beep.wav", UriKind.Relative));
                if (resourceStream != null)
                {
                    scanEffect = SoundEffect.FromStream(resourceStream.Stream);
                }
            }

            timer.Start();
        }
Example #32
0
        // When the pivot has changed we need to act accordingly.
        private void PivotSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = this.mainPivot.SelectedIndex;

            if (index == 0)
            {
                List <BarcodeItem> main = new List <BarcodeItem>(AppContext.appContext.itemList);
                this.FirstListBox.ItemsSource = main;
            }
            else
            {
                //We need to initialize the camera.
                if (this.camera == null)
                {
                    if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true)
                    {
                        this.camera                      = new PhotoCamera(CameraType.Primary);
                        this.camera.Initialized         += OnPhotoCameraInitialized;
                        CameraButtons.ShutterKeyPressed += OnButtonFullPress;
                        // The event is fired when the viewfinder is tapped (for focus).
                        CodeScannerCanvas.Tap             += new EventHandler <GestureEventArgs>(FocusTapped);
                        this.camera.CaptureImageAvailable += new EventHandler <Microsoft.Devices.ContentReadyEventArgs>(CameraPictureReady);
                        viewfinderBrush.SetSource(this.camera);
                    }
                }
            }
        }
Example #33
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Emulator)
            {
                MessageBox.Show("You must deploy this sample to a device, instead of the emulator so that you can get a video stream including a barcode/QR code");
                this.IsEnabled = false;
                base.NavigationService.GoBack();
            }
            else
            {
                string type = "";
                if (NavigationContext.QueryString.TryGetValue("type", out type) && type == "qrcode")
                {
                    _reader = new QRCodeReader();
                }
                else
                {
                    _reader = new EAN13Reader();
                }

                _photoCamera              = new PhotoCamera();
                _photoCamera.Initialized += new EventHandler <CameraOperationCompletedEventArgs>(cam_Initialized);
                _videoBrush.SetSource(_photoCamera);
                BarCodeRectInitial();
                base.OnNavigatedTo(e);
            }
        }
Example #34
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            // Check to see if the camera is available on the phone.
            if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) ||
                (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) == true))
            {
                // Initialize the default camera.
                cam = new Microsoft.Devices.PhotoCamera();

                //Event is fired when the PhotoCamera object has been initialized
                cam.Initialized += new EventHandler <Microsoft.Devices.CameraOperationCompletedEventArgs>(cam_Initialized);

                //Set the VideoBrush source to the camera
                viewfinderBrush.SetSource(cam);
            }
            else
            {
                // The camera is not supported on the phone.
                this.Dispatcher.BeginInvoke(delegate()
                {
                    // Write message.
                    txtDebug.Text = "A Camera is not available on this phone.";
                });
            }
        }
      protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
      {
         base.OnNavigatedTo(e);

         // Delayed due to Camera init bug in WP71 SDK Beta 2
         // See http://forums.create.msdn.com/forums/p/85830/516843.aspx
         Dispatcher.BeginInvoke(() =>
                                {

                                   // Initialize the webcam
                                   photoCamera = new PhotoCamera();
                                   photoCamera.Initialized += PhotoCameraInitialized;
                                   CameraButtons.ShutterKeyHalfPressed += PhotoCameraButtonHalfPress;
                                   isInitialized = false;
                                   isDetecting = false;

                                   // Fill the Viewport Rectangle with the VideoBrush
                                   var vidBrush = new VideoBrush();
                                   vidBrush.SetSource(photoCamera);
                                   Viewport.Fill = vidBrush;

                                   // Start timer
                                   dispatcherTimer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(50)};
                                   dispatcherTimer.Tick += (sender, e1) => Detect();
                                   dispatcherTimer.Start();
                                });
      }
Example #36
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

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

                CameraButtons.ShutterKeyHalfPressed += OnButtonHalfPress;
            }

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

            if (scanEffect == null){

                var resourceStream = Application.GetResourceStream(new System.Uri("Plugins/com.phonegap.plugins.barcodescanner/beep.wav", UriKind.Relative));
                if (resourceStream != null)
                {
                    scanEffect = SoundEffect.FromStream(resourceStream.Stream);
                }
            }

            timer.Start();
        }
        /// <summary>
        /// Called when the control is loaded.
        /// </summary>
        private void This_Loaded(object sender, EventArgs e)
        {
            try
            {
                // camera init must be done here
                _camera              = new PhotoCamera(CameraType.Primary);
                _camera.Initialized += Camera_Initialized;
                PreviewVideo.SetSource(_camera);

                _frame = (PhoneApplicationFrame)Application.Current.RootVisual;
                _frame.BackKeyPress += Frame_BackKeyPress;

                _underPage = (PhoneApplicationPage)_frame.Content;

                _underPageTrayVisible   = SystemTray.GetIsVisible(_underPage);
                _underPageAppBarVisible = _underPage.ApplicationBar.IsVisible;

                SystemTray.SetIsVisible(_underPage, false);
                _underPage.ApplicationBar.IsVisible = false;
            }
            catch
            {
                ErrorMessage.Visibility = Visibility.Visible;
            }
        }
Example #38
0
        // Load data for the ViewModel Items
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }

            // Initialize the camera object
            _phoneCamera = new PhotoCamera();
            _phoneCamera.Initialized += cam_Initialized;
            _phoneCamera.AutoFocusCompleted += _phoneCamera_AutoFocusCompleted;

            CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;

            //Display the camera feed in the UI
            viewfinderBrush.SetSource(_phoneCamera);


            // 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();

            viewfinderCanvas.Tap += new EventHandler<GestureEventArgs>(focus_Tapped);

            base.OnNavigatedTo(e);
        }
Example #39
0
        public void SetupPage()
        {
            //turn on the display of the board and models
            SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true);

            //Run the detection separate from the update
            dispatcherTimer.Start();

            // Create a timer for this page
            timer.Start();

            //see if user was placed into check
            if ((GameStateManager.getInstance().getGameState().black.in_check&& GameStateManager.getInstance().getCurrentPlayer() == ChessPiece.Color.BLACK) || (GameStateManager.getInstance().getGameState().white.in_check&& GameStateManager.getInstance().getCurrentPlayer() == ChessPiece.Color.WHITE))
            {
                handleError("You have been placed into check by your opponent.");
            }

            //if the state of the game has not yet been loaded, load it now before displaying board
            if (!stateHasBeenLoaded)
            {
                GameState.getInstance().loadState(GameStateManager.getInstance().getGameState());
                stateHasBeenLoaded = true;
            }

            //Initialize the camera
            photoCamera              = new PhotoCamera();
            photoCamera.Initialized += new EventHandler <CameraOperationCompletedEventArgs>(photoCamera_Initialized);
            ViewFinderBrush.SetSource(photoCamera);

            setupFinished = true;
        }
Example #40
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) ||
             (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) == true))
            {
                if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing))
                {
                    cam = new Microsoft.Devices.PhotoCamera(CameraType.FrontFacing);
                }
                else
                {
                    cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
                }

                viewfinderBrush.SetSource(cam);
                cam.Initialized += cam_Initialized;
                cam.CaptureCompleted += cam_CaptureCompleted;
                cam.CaptureImageAvailable += cam_CaptureImageAvailable;
                cam.AutoFocusCompleted += cam_AutoFocusCompleted;

                // 当按下快门按钮并保持大约 800 毫秒时。短于该时间的半按压将不会触发该事件。
                CameraButtons.ShutterKeyHalfPressed += OnButtonHalfPress;
                // 当快门按钮收到一个完全按压时。
                CameraButtons.ShutterKeyPressed += OnButtonFullPress;
                // 当松开快门按钮时。
                CameraButtons.ShutterKeyReleased += OnButtonRelease;
            }

            base.OnNavigatedTo(e);
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true)
            {
                camera = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
                photoViewfinderVideoBrush.SetSource(camera);

                photoViewfinderVideoBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 };

                camera.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(captureCompletedHandler);
                camera.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(captureImageAvailableHandler);
                camera.CaptureThumbnailAvailable += new EventHandler<ContentReadyEventArgs>(captureThumbnailAvailableHandler);
                camera.AutoFocusCompleted += new EventHandler<CameraOperationCompletedEventArgs>(autoFocusCompletedHandler);

                CameraButtons.ShutterKeyHalfPressed += onButtonHalfPressHandler;
                CameraButtons.ShutterKeyPressed += onButtonFullPressHandler;
                CameraButtons.ShutterKeyReleased += onButtonReleaseHandler;

            }
            else
            {
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                 {
                     MessageBox.Show("Camera not supported in this phone");
                 });

                NavigationService.GoBack();
            }
        }
        private PhotoCamera InitCamera()
        {
            var camera = new PhotoCamera();

            camera.Initialized        += Camera_Initialized;
            camera.AutoFocusCompleted += Camera_AutoFocusCompleted;
            return(camera);
        }
Example #43
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _photoCamera = new PhotoCamera();
              _photoCamera.Initialized += OnPhotoCameraInitialized;
              _previewVideo.SetSource(_photoCamera);

              base.OnNavigatedTo(e);
        }
 void CleanUpCamera()
 {
     CameraButtons.ShutterKeyPressed -= cameraButtons_ShutterKeyPressed;
     camera.CaptureImageAvailable    -= camera_CaptureImageAvailable;
     camera.CaptureCompleted         -= camera_CaptureCompleted;
     camera.Dispose();
     camera = null;
 }
Example #45
0
        private void InitCamera()
        {
            _camera              = new PhotoCamera(CameraType.Primary);
            _camera.Initialized += _camera_Initialized;

            VideoViewfinderBrush.SetSource(_camera);
            VideoViewfinderTransform.Rotation = _camera.Orientation;
        }
Example #46
0
		private void InitCamera()
		{
			_camera = new PhotoCamera(CameraType.Primary);
			_camera.Initialized += _camera_Initialized;

			VideoViewfinderBrush.SetSource(_camera);
			VideoViewfinderTransform.Rotation = _camera.Orientation;
		}
Example #47
0
 // Code for initialization and setting the source for the viewfinder
 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
 {
     camera = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
     // Event is fired when PhotoCamera object has beeninitialized.
     camera.Initialized += new EventHandler<Microsoft.Devices.CameraOperationCompletedEventArgs>(cam_Initialized);
     camera.AutoFocusCompleted += new EventHandler<CameraOperationCompletedEventArgs>(cam_AutoFocusCompleted);
     //Set the VideoBrush source to the video
     mainCameraBrush.SetSource(camera);
 }
Example #48
0
 public camera()
 {
     InitializeComponent();
     mediaLib = new MediaLibrary();
     myCam = new PhotoCamera(CameraType.Primary);
     myCam.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(captureCompleted);
     myCam.CaptureImageAvailable += new EventHandler<ContentReadyEventArgs>(captureImageAvailable);
     viewfinderBrush.SetSource(myCam);
 }
Example #49
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);
        }
 protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
 {
     //while (_captureInProgress) { };
     _camera.AutoFocusCompleted -= OnCameraAutoFocusCompleted;
     _camera.CaptureImageAvailable -= OnCaptureImageAvailable;
     _camera.Initialized -= OnCameraInitialized;
     _camera.Dispose();
     _camera = null;
     base.OnNavigatedFrom(e);
 }
Example #51
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);
        }
Example #52
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            camera = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
            camera.Initialized += new EventHandler<CameraOperationCompletedEventArgs>(camera_Initialized);
            camera.AutoFocusCompleted += new EventHandler<CameraOperationCompletedEventArgs>(camera_AutoFocusCompleted);
            previewVideo.SetSource(camera);

            // Prevent screen lock
            PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
        }
Example #53
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);
        }
Example #55
0
 public void InitCamera(VideoBrush CurrentVideoBrush)
 {
    
     this.Camera = new PhotoCamera(CameraType.Primary);
   
     this.Camera.Initialized += Camera_Initialized;
     this.Camera.CaptureCompleted += Camera_CaptureCompleted;
     this.Camera.CaptureImageAvailable += Camera_CaptureImageAvailable;
     //Set the VideoBrush source to the camera.
     CurrentVideoBrush.SetSource(Camera);
 }
 // Constructor
 public MainPage()
 {
     InitializeComponent();
     // Initialize the list of TextBlock and Vector3 objects.
     textBlocks = new List<TextBlock>();
     points = new List<Vector3>();
     //gobutton.SetValue(Canvas.ZIndexProperty, 2);
     //searchbar.SetValue(Canvas.ZIndexProperty, 2);
     cam = new Microsoft.Devices.PhotoCamera();
     videoBrush.SetSource(cam);
 }
Example #57
0
        public Camera(VideoBrush video, int photocount)
        {
            if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true)
            {
                // There is a camera. Which I already know. But useful if I decide to use this in any other apps.

                cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
                photoname = photocount;
                videobrush = video;

            }
        }
Example #58
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            _cam = new PhotoCamera();

            _cam.Initialized += new EventHandler<CameraOperationCompletedEventArgs>(cam_Initialized);
            _cam.AutoFocusCompleted += new EventHandler<CameraOperationCompletedEventArgs>(cam_AutoFocusCompleted);

            video.Fill = _videoBrush;
            _videoBrush.SetSource(_cam);

            base.OnNavigatedTo(e);
        }
Example #59
0
 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
 {
     VideoCanvas.Visibility = Visibility.Visible;
     Result.Visibility = Visibility.Collapsed;
     if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
     {
         cam = new PhotoCamera(CameraType.Primary);
         cam.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(cam_CaptureCompleted);
         videoBrush.SetSource(cam);
         previewTransform.Rotation = cam.Orientation;
     }
 }
        public MainPage()
        {
            InitializeComponent();

            _phoneCamera = new PhotoCamera();
            _phoneCamera.Initialized += cam_Initialized;

            VideoBrushBackground.SetSource(_phoneCamera);

            _scanTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) };
            _scanTimer.Tick += (o, arg) => ScanForBarcode();
        }