Exemple #1
0
        async private void GetPreview()
        {
            Windows.Media.Capture.MediaCapture takePhotoManager = new Windows.Media.Capture.MediaCapture();
            await takePhotoManager.InitializeAsync();

            // start previewing
            PhotoPreview.Source = takePhotoManager;
            await takePhotoManager.StartPreviewAsync();

            // to stop it
            await takePhotoManager.StopPreviewAsync();

            ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();

            // a file to save a photo
            StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                "Photo.jpg", CreationCollisionOption.ReplaceExisting);

            await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file);

            // Get photo as a BitmapImage
            BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));

            // imagePreivew is a <Image> object defined in XAML
            imagePreivew.Source = bmpImage;
        }