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; } }
private async Task RestartPreviewAsync() { Windows.Media.Capture.MediaCapture capture = capturePreview.Source; if (capture == null) { return; //以前はキャプチャしていなかった } // キャプチャオブジェクトを作り直し capture = new Windows.Media.Capture.MediaCapture(); try { // Webカメラの初期化 await capture.InitializeAsync(); // 作り直した MediaCapture インスタンスを CaptureElement コントロールに設定する capturePreview.Source = capture; // 本当はフィルタも再設定しなければいけない // プレビューを再開する await capture.StartPreviewAsync(); } catch { //(void) } }
private async void buttonPreviewClick(object sender, RoutedEventArgs e) { // 静止画撮影、動画録画をおこなうキャプチャーオブジェクト var _capture = new Windows.Media.Capture.MediaCapture(); try { // Webカメラの初期化 await _capture.InitializeAsync(); } catch (UnauthorizedAccessException ex) { // "アクセスが拒否されました。 (HRESULT からの例外: 0x80070005 (E_ACCESSDENIED))" // Web カメラがユーザーに許可されていないと、 // UnauthorizedAccessException が出る。 ShowRequestMessageAsync(ex); return; } // MediaCapture インスタンスを CaptureElement コントロールに設定する capturePreview.Source = _capture; // プレビューを開始する await _capture.StartPreviewAsync(); }
private async void buttonPreviewWithVideoStabilizationClick(object sender, RoutedEventArgs e) { var _capture = new Windows.Media.Capture.MediaCapture(); try { await _capture.InitializeAsync(); } catch (UnauthorizedAccessException ex) { ShowRequestMessageAsync(ex); return; } // キャプチャしたビデオに手ブレ補正効果を追加する // http://msdn.microsoft.com/ja-jp/library/windows/apps/xaml/hh868169.aspx await _capture.AddEffectAsync( Windows.Media.Capture.MediaStreamType.VideoRecord, Windows.Media.VideoEffects.VideoStabilization, null); capturePreview.Source = _capture; await _capture.StartPreviewAsync(); }
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; }