本文整理汇总了C#中Windows.Media.Capture.MediaCapture.AddEffectAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MediaCapture.AddEffectAsync方法的具体用法?C# MediaCapture.AddEffectAsync怎么用?C# MediaCapture.AddEffectAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Media.Capture.MediaCapture
的用法示例。
在下文中一共展示了MediaCapture.AddEffectAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitiateCameraCaptureObject
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;
}
示例2: InitializeCaptureAsync
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;
}
示例3: StartMediaCaptureRecord_Click
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;
}
示例4: StartMediaCapturePreview_Click
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;
}
示例5: InitializeCaptureAsync
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;
}