Пример #1
0
        async public void Toggle(Windows.UI.Xaml.Controls.CaptureElement preview)
        {
            if (CallState == CallState.NoCall)
            {
                // Start call
                voipCall = voipCallCoordinator.RequestNewOutgoingCall("/ActiveCallContext", "Jack And Jill", "Whazzuuupppp", Windows.ApplicationModel.Calls.VoipPhoneCallMedia.Audio);

                captureElement = new Windows.Media.Capture.MediaCapture();
                await captureElement.InitializeAsync();

                preview.Source = captureElement;
                await captureElement.StartPreviewAsync();

                voipCall.NotifyCallActive();

                CallState = CallState.InCall;
            }
            else if (CallState == CallState.InCall)
            {
                // Stop call
                await captureElement.StopPreviewAsync();

                preview.Source = null;

                captureElement.Dispose();
                captureElement = null;

                voipCall.NotifyCallEnded();
                voipCall = null;

                CallState = CallState.NoCall;
            }
        }
Пример #2
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;
        }