Пример #1
0
        private void Initialize()
        {
            StatusTextBlock.Text = AppResources.MainPage_Status_InitializingCamera;

            _cameraEffect = new Effects {
                PhotoCaptureDevice = App.Camera, GlobalAlpha = 0.5
            };
            _cameraEffect.SetTexture(App.Texture.File);

            if (App.Texture.IsPositional)
            {
                DragHintText.Visibility  = Visibility.Visible;
                PinchHintText.Visibility = Visibility.Visible;

                _angle           = 0;
                _initialAngle    = 0;
                _scale           = DefaultScale;
                _position        = new Point(0.5, 0.5);
                _initialPosition = new Point(0.5, 0.5);

                RefreshTargetArea();
            }
            else
            {
                DragHintText.Visibility  = Visibility.Collapsed;
                PinchHintText.Visibility = Visibility.Collapsed;
            }

            LevelSlider.Value = 0.5;

            _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;
        }
Пример #2
0
        private void Uninitialize()
        {
            StatusTextBlock.Text = "";

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

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

            _cameraEffect = null;
        }