private void Uninitialize()
        {
            StatusTextBlock.Text = "";

            if (_mediaElement != null)
            {
                _mediaElement.Source = null;
                _mediaElement        = null;
            }

            if (_cameraStreamSource != null)
            {
                _cameraStreamSource.FrameRateChanged -= CameraStreamSource_FPSChanged;
                _cameraStreamSource = null;
            }

            _cameraEffect = null;
        }
        private async void Initialize()
        {
            StatusTextBlock.Text = AppResources.MainPage_StatusTextBlock_StartingCamera;

            _cameraEffect = new Effects()
            {
                PhotoCaptureDevice = App.Camera
            };

            _cameraStreamSource = new CameraStreamSource(_cameraEffect, App.Camera.CaptureResolution);
            _cameraStreamSource.FrameRateChanged += CameraStreamSource_FPSChanged;

            _mediaElement = new MediaElement {
                Stretch = Stretch.UniformToFill, BufferingTime = new TimeSpan(0)
            };
            _mediaElement.SetSource(_cameraStreamSource);

            // Using VideoBrush in XAML instead of MediaElement, because otherwise
            // CameraStreamSource.CloseMedia() does not seem to be called by the framework:/

            BackgroundVideoBrush.SetSource(_mediaElement);

            StatusTextBlock.Text = _cameraEffect.EffectName;
        }
        private void Uninitialize()
        {
            StatusTextBlock.Text = "";

            if (_mediaElement != null)
            {
                _mediaElement.Source = null;
                _mediaElement = null;
            }

            if (_cameraStreamSource != null)
            {
                _cameraStreamSource.FrameRateChanged -= CameraStreamSource_FPSChanged;
                _cameraStreamSource = null;
            }

            _cameraEffect = null;

            if (_photoCaptureDevice != null)
            {
                _photoCaptureDevice.Dispose();
                _photoCaptureDevice = null;
            }
        }
        private async void Initialize()
        {
            StatusTextBlock.Text = AppResources.MainPage_StatusTextBlock_StartingCamera;

            var resolution = PhotoCaptureDevice.GetAvailablePreviewResolutions(CameraSensorLocation.Back).Last();

            _photoCaptureDevice = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, resolution);

            await _photoCaptureDevice.SetPreviewResolutionAsync(resolution);

            _cameraEffect = new NokiaImagingSDKEffects();
            _cameraEffect.PhotoCaptureDevice = _photoCaptureDevice;

            _cameraStreamSource = new CameraStreamSource(_cameraEffect, resolution);
            _cameraStreamSource.FrameRateChanged += CameraStreamSource_FPSChanged;

            _mediaElement = new MediaElement();
            _mediaElement.Stretch = Stretch.UniformToFill;
            _mediaElement.BufferingTime = new TimeSpan(0);
            _mediaElement.SetSource(_cameraStreamSource);

            // Using VideoBrush in XAML instead of MediaElement, because otherwise
            // CameraStreamSource.CloseMedia() does not seem to be called by the framework:/

            BackgroundVideoBrush.SetSource(_mediaElement);

            _cameraEffect.PreviousEffect();
            StatusTextBlock.Text = _cameraEffect.EffectName;
        }
Пример #5
0
        private async void Initialize()
        {
            StatusTextBlock.Text = AppResources.MainPage_StatusTextBlock_StartingCamera;

            _cameraEffect = new Effects() {PhotoCaptureDevice = App.Camera};
            
            _cameraStreamSource = new CameraStreamSource(_cameraEffect, App.Camera.CaptureResolution);
            _cameraStreamSource.FrameRateChanged += CameraStreamSource_FPSChanged;

            _mediaElement = new MediaElement {Stretch = Stretch.UniformToFill, BufferingTime = new TimeSpan(0)};
            _mediaElement.SetSource(_cameraStreamSource);

            // Using VideoBrush in XAML instead of MediaElement, because otherwise
            // CameraStreamSource.CloseMedia() does not seem to be called by the framework:/

            BackgroundVideoBrush.SetSource(_mediaElement);

            StatusTextBlock.Text = _cameraEffect.EffectName;
        }
Пример #6
0
    /// <summary>
    /// Opens and sets up the camera if not already. Creates a new
    /// CameraStreamSource with an effect and shows it on the screen via
    /// the media element.
    /// </summary>
    private async void Initialize() {
      Debug.WriteLine("MainPage.Initialize()");
      var mediaElementSize = new Size(MediaElementWidth, MediaElementHeight);

      if (_camera == null) {
        // Resolve the capture resolution and open the camera
        var captureResolutions =
          PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);

        var selectedCaptureResolution =
          captureResolutions.Where(
            resolution => Math.Abs(AspectRatio - resolution.Width/resolution.Height) <= 0.1)
                            .OrderBy(resolution => resolution.Width).Last();

        _camera = await PhotoCaptureDevice.OpenAsync(
          CameraSensorLocation.Back, selectedCaptureResolution);

        // Set the image orientation prior to encoding
        _camera.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation,
                           _camera.SensorLocation == CameraSensorLocation.Back
                           ? _camera.SensorRotationInDegrees : -_camera.SensorRotationInDegrees);

        // Resolve and set the preview resolution
        var previewResolutions =
          PhotoCaptureDevice.GetAvailablePreviewResolutions(CameraSensorLocation.Back);

        Size selectedPreviewResolution =
          previewResolutions.Where(
            resolution => Math.Abs(AspectRatio - resolution.Width/resolution.Height) <= 0.1)
                            .Where(resolution => (resolution.Height >= mediaElementSize.Height)
                                                 && (resolution.Width >= mediaElementSize.Width))
                            .OrderBy(resolution => resolution.Width).First();

        await _camera.SetPreviewResolutionAsync(selectedPreviewResolution);

        _cameraEffect.CaptureDevice = _camera;
      }

      if (_mediaElement == null) {
        _mediaElement = new MediaElement {
          Stretch = Stretch.UniformToFill, 
          BufferingTime = new TimeSpan(0)
        };
        _mediaElement.Tap += OnMyCameraMediaElementTapped;
        _source = new CameraStreamSource(_cameraEffect, mediaElementSize);
        _mediaElement.SetSource(_source);
        MediaElementContainer.Children.Add(_mediaElement);
        _source.FPSChanged += OnFPSChanged;
      }

      // Show the index and the name of the current effect
      if (_cameraEffect is NokiaImagingSDKEffects) {
        var effects =
          _cameraEffect as NokiaImagingSDKEffects;

        EffectNameTextBlock.Text =
          (effects.EffectIndex + 1) + "/"
          + NokiaImagingSDKEffects.NumberOfEffects
          + ": " + effects.EffectName;
      } else {
        EffectNameTextBlock.Text = _cameraEffect.EffectName;
      }
    }