private void InitializeCamera()
        {
            var captureResolutions = PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).ToArray();
            var previewResolutions = PhotoCaptureDevice.GetAvailablePreviewResolutions(CameraSensorLocation.Back).ToArray();

            Windows.Foundation.Size captureResolution = new Windows.Foundation.Size(640, 480);
            Windows.Foundation.Size previewResolution = new Windows.Foundation.Size(640, 480);

            try
            {
                captureResolution = GetFirstWideResolution(captureResolutions);
                previewResolution = GetFirstWideResolution(previewResolutions);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to get wide resolution for viewfinder, using 640x480");
            }

            var task = PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, captureResolution).AsTask();

            task.Wait();

            _device = task.Result;
            _device.SetPreviewResolutionAsync(previewResolution).AsTask().Wait();

            var objectResolutionSide = _device.PreviewResolution.Height * (ReaderBorder.Height - 2 * ReaderBorder.Margin.Top) / 480;
            var objectResolution     = new Windows.Foundation.Size(objectResolutionSide, objectResolutionSide);
            var focusRegionSize      = new Windows.Foundation.Size(objectResolutionSide, objectResolutionSide);
            var objectSize           = OpticalReaderLib.OpticalReaderTask.Instance.ObjectSize;

            if (objectSize.Width * objectSize.Height > 0)
            {
                var parameters = OpticalReaderLib.Utilities.GetSuggestedParameters(_device.PreviewResolution, _device.SensorRotationInDegrees, objectSize, objectResolution);

                _zoom = Math.Max(parameters.Zoom, 1.0);
            }
            else
            {
                _zoom = 1.0;
            }

            var centerPoint = new Windows.Foundation.Point(previewResolution.Width / 2, previewResolution.Height / 2);

            _device.FocusRegion = new Windows.Foundation.Rect(
                centerPoint.X - focusRegionSize.Width / 2, centerPoint.Y - focusRegionSize.Height / 2,
                focusRegionSize.Width, focusRegionSize.Height);

            ViewfinderVideoBrush.SetSource(_device);
        }
Exemple #2
0
        /// <summary>
        /// Synchronously initializes the photo capture device for a high resolution photo capture.
        /// Viewfinder video stream is sent to a VideoBrush element called ViewfinderVideoBrush, and
        /// device hardware capture key is wired to the CameraButtons_ShutterKeyHalfPressed and
        /// CameraButtons_ShutterKeyPressed methods.
        /// </summary>
        private void InitializeCamera()
        {
            Windows.Foundation.Size captureResolution;

            var deviceName = DeviceStatus.DeviceName;

            if (deviceName.Contains("RM-875") || deviceName.Contains("RM-876") || deviceName.Contains("RM-877"))
            {
                captureResolution = new Windows.Foundation.Size(7712, 4352); // 16:9
                //captureResolution = new Windows.Foundation.Size(7136, 5360); // 4:3
            }
            else if (deviceName.Contains("RM-937") || deviceName.Contains("RM-938") || deviceName.Contains("RM-939"))
            {
                captureResolution = new Windows.Foundation.Size(5376, 3024); // 16:9
                //captureResolution = new Windows.Foundation.Size(4992, 3744); // 4:3
            }
            else
            {
                captureResolution = PhotoCaptureDevice.GetAvailableCaptureResolutions(SENSOR_LOCATION).First();
            }

            var task = PhotoCaptureDevice.OpenAsync(SENSOR_LOCATION, captureResolution).AsTask();

            task.Wait();

            _device = task.Result;
            _device.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true);

            if (_flashButton != null)
            {
                SetFlashState(_flashState);
            }

            AdaptToOrientation();

            ViewfinderVideoBrush.SetSource(_device);

            if (PhotoCaptureDevice.IsFocusSupported(SENSOR_LOCATION))
            {
                Microsoft.Devices.CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;
            }

            Microsoft.Devices.CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed;
        }