public AddEffectAsync ( [ mediaStreamType, [ effectActivationID, [ effectSettings ) : IAsyncAction | ||
mediaStreamType | [ | |
effectActivationID | [ | |
effectSettings | [ | |
return | IAsyncAction |
internal async void addEffectToImageStream() { if ((m_mediaCaptureMgr.MediaCaptureSettings.VideoDeviceCharacteristic != Windows.Media.Capture.VideoDeviceCharacteristic.AllStreamsIdentical) && (m_mediaCaptureMgr.MediaCaptureSettings.VideoDeviceCharacteristic != Windows.Media.Capture.VideoDeviceCharacteristic.PreviewPhotoStreamsIdentical) && (m_mediaCaptureMgr.MediaCaptureSettings.VideoDeviceCharacteristic != Windows.Media.Capture.VideoDeviceCharacteristic.RecordPhotoStreamsIdentical)) { IMediaEncodingProperties props2 = m_mediaCaptureMgr.VideoDeviceController.GetMediaStreamProperties(Windows.Media.Capture.MediaStreamType.Photo); if (props2.GetType().Equals("Image")) //Cant add an effect to an image type { //Change the media type on the stream System.Collections.Generic.IReadOnlyList <IMediaEncodingProperties> supportedPropsList = m_mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(Windows.Media.Capture.MediaStreamType.Photo); int i = 0; while (i++ < supportedPropsList.Count) { if (supportedPropsList[i].Type.Equals("Video")) { await m_mediaCaptureMgr.VideoDeviceController.SetMediaStreamPropertiesAsync(Windows.Media.Capture.MediaStreamType.Photo, supportedPropsList[i]); ShowStatusMessage("Change type on image pin successful"); await m_mediaCaptureMgr.AddEffectAsync(Windows.Media.Capture.MediaStreamType.Photo, "GrayscaleTransform.GrayscaleEffect", null); ShowStatusMessage("Add effect to photo successful"); m_bEffectAddedToPhoto = true; chkAddRemoveEffect.IsEnabled = true; break; } } chkAddRemoveEffect.IsEnabled = true; } else { await m_mediaCaptureMgr.AddEffectAsync(Windows.Media.Capture.MediaStreamType.Photo, "GrayscaleTransform.GrayscaleEffect", null); ShowStatusMessage("Add effect to photo successful"); chkAddRemoveEffect.IsEnabled = true; m_bEffectAddedToPhoto = true; } } else { chkAddRemoveEffect.IsEnabled = true; } }
// </SnippetMediaCaptureVideo_MirroringComplete> //<SnippetAddSlowMotionEffectCS> public async void AddSlowMotionEffect() { Windows.Media.Effects.SlowMotionEffectDefinition slowMotionEffectDefinition = new Windows.Media.Effects.SlowMotionEffectDefinition(); // Setter and Getter for TimeStretchRate. slowMotionEffectDefinition.TimeStretchRate = 2; // Add the effect using the AddEffectAsync overloaded method await _mediaCapture.AddEffectAsync( MediaStreamType.VideoRecord, slowMotionEffectDefinition.ActivatableClassId, slowMotionEffectDefinition.Properties); }
// Enables the grayscale effect. private async void AddRemoveEffect_Checked(object sender, RoutedEventArgs e) { try { AddRemoveEffect.IsEnabled = false; await mediaCapture.AddEffectAsync(MediaStreamType.Photo, "GrayscaleTransform.GrayscaleEffect", null); ShowStatusMessage("Add effect to video preview successful"); AddRemoveEffect.IsEnabled = true; } catch (Exception ex) { ShowExceptionMessage(ex); } }
private async Task InitiateCameraCaptureObject(Panel deviceLocation) { try { if (_bInitializingCamera || _cameraCapture != null) return; _bInitializingCamera = true; await InitCaptureSettings(deviceLocation); _cameraCapture = new MediaCapture(); await _cameraCapture.InitializeAsync(_captureInitSettings); //Enable QR Detector if (_qrDetectionModeEnabled) { var formats = _cameraCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo); var format = (VideoEncodingProperties)formats.OrderBy((item) => { var props = (VideoEncodingProperties)item; return Math.Abs(props.Height - ActualWidth) + Math.Abs(props.Width - ActualHeight); }).First(); await _cameraCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, format); var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, format.Width >= format.Height ? format.Width : format.Height, AnalyzeImage); await _cameraCapture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties); _barcodeReader = _barcodeReader ?? new BarcodeReader { Options = new DecodingOptions { PossibleFormats = new[] { BarcodeFormat.QR_CODE, BarcodeFormat.CODE_128 }, TryHarder = true } }; } PhotoPreview.Source = _cameraCapture; await _cameraCapture.StartPreviewAsync(); _cameraCapture.Failed += CameraCaptureOnFailed; _scannerAutoFocus = await ScannerAutoFocus.StartAsync(_cameraCapture.VideoDeviceController.FocusControl); _cameraCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees); } catch (Exception ex) { WindowsPhoneUtils.Log(ex.Message); } _bInitializingCamera = false; }
private async Task InitializeCaptureAsync() { if (m_initializing || (m_capture != null)) { return; } m_initializing = true; try { var settings = new MediaCaptureInitializationSettings { VideoDeviceId = await GetBackOrDefaulCameraIdAsync(), StreamingCaptureMode = StreamingCaptureMode.Video }; var capture = new MediaCapture(); await capture.InitializeAsync(settings); // Select the capture resolution closest to screen resolution var formats = capture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview); var format = (VideoEncodingProperties)formats.OrderBy((item) => { var props = (VideoEncodingProperties)item; return Math.Abs(props.Width - this.ActualWidth) + Math.Abs(props.Height - this.ActualHeight); }).First(); await capture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, format); // Make the preview full screen var scale = Math.Min(this.ActualWidth / format.Width, this.ActualHeight / format.Height); Preview.Width = format.Width; Preview.Height = format.Height; Preview.RenderTransformOrigin = new Point(.5, .5); Preview.RenderTransform = new ScaleTransform { ScaleX = scale, ScaleY = scale }; BarcodeOutline.Width = format.Width; BarcodeOutline.Height = format.Height; BarcodeOutline.RenderTransformOrigin = new Point(.5, .5); BarcodeOutline.RenderTransform = new ScaleTransform { ScaleX = scale, ScaleY = scale }; // Enable QR code detection var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, 640, AnalyzeBitmap); await capture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties); // Start preview m_time.Restart(); Preview.Source = capture; await capture.StartPreviewAsync(); capture.Failed += capture_Failed; m_autoFocus = await ContinuousAutoFocus.StartAsync(capture.VideoDeviceController.FocusControl); m_capture = capture; } catch (Exception e) { TextLog.Text = String.Format("Failed to start the camera: {0}", e.Message); } m_initializing = false; }
private async void StartMediaCapturePreview_Click(object sender, RoutedEventArgs e) { StartCaptureElementPreview.IsEnabled = false; // Skip if no camera var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); if (devices.Count == 0) { return; } var capture = new MediaCapture(); await capture.InitializeAsync(new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Video }); var definition = await CreateEffectDefinitionAsync( (VideoEncodingProperties)capture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) ); await capture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties); CapturePreview.Source = capture; await capture.StartPreviewAsync(); StartCaptureElementPreview.IsEnabled = true; }
private async void StartMediaCaptureRecord_Click(object sender, RoutedEventArgs e) { StartCaptureElementRecord.IsEnabled = false; // Skip if no camera var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); if (devices.Count == 0) { return; } StorageFile destination = await KnownFolders.VideosLibrary.CreateFileAsync("VideoEffectsTestApp.MediaCapture.mp4", CreationCollisionOption.ReplaceExisting); var capture = new MediaCapture(); await capture.InitializeAsync(new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Video }); var definition = await CreateEffectDefinitionAsync( (VideoEncodingProperties)capture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoRecord) ); await capture.AddEffectAsync(MediaStreamType.VideoRecord, definition.ActivatableClassId, definition.Properties); await capture.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga), destination); await Task.Delay(3000); await capture.StopRecordAsync(); StartCaptureElementRecord.IsEnabled = true; }
private async Task InitializeCaptureAsync() { if (isMediaCaptureInitializing || (mediaCapture != null)) return; isMediaCaptureInitializing = true; try { var settings = new MediaCaptureInitializationSettings { VideoDeviceId = await GetBackOrDefaulCameraIdAsync(), StreamingCaptureMode = StreamingCaptureMode.Video }; var newMediaCapture = new MediaCapture(); await newMediaCapture.InitializeAsync(settings); // Select the capture resolution closest to screen resolution var formats = newMediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview); var format = (VideoEncodingProperties)formats.OrderBy((item) => { var props = (VideoEncodingProperties)item; return Math.Abs(props.Width - this.ActualHeight) + Math.Abs(props.Height - this.ActualWidth); }).First(); Debug.WriteLine("{0} x {1}", format.Width, format.Height); await newMediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, format); // Disable flash control if supported if (newMediaCapture.VideoDeviceController.FlashControl.Supported) newMediaCapture.VideoDeviceController.FlashControl.Enabled = false; // Prepare bitmap for reports bitmapWithBarcode = new WriteableBitmap((int)format.Width, (int)format.Height); // Make the preview full screen Preview.Width = this.ActualHeight; Preview.Height = this.ActualWidth; // Enable QR code detection var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, Math.Min(format.Width, 800), AnalyzeBitmap); await newMediaCapture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties); // Start preview Preview.Source = newMediaCapture; await newMediaCapture.StartPreviewAsync(); newMediaCapture.Failed += OnMediaCaptureFailed; autoFocus = await ContinuousAutoFocus.StartAsync(newMediaCapture.VideoDeviceController.FocusControl); mediaCapture = newMediaCapture; } catch (Exception e) { Debug.WriteLine("Failed to start the camera: {0}", e.Message); } isMediaCaptureInitializing = false; }