本文整理汇总了C#中Windows.Media.Capture.MediaCapture.StartPreviewAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MediaCapture.StartPreviewAsync方法的具体用法?C# MediaCapture.StartPreviewAsync怎么用?C# MediaCapture.StartPreviewAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Media.Capture.MediaCapture
的用法示例。
在下文中一共展示了MediaCapture.StartPreviewAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartPreview_Click
/// <summary>
/// This is the click handler for the 'StartPreview' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void StartPreview_Click(object sender, RoutedEventArgs e)
{
try
{
// Check if the machine has a webcam
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (devices.Count > 0)
{
rootPage.NotifyUser("", NotifyType.ErrorMessage);
if (mediaCaptureMgr == null)
{
// Using Windows.Media.Capture.MediaCapture APIs to stream from webcam
mediaCaptureMgr = new MediaCapture();
await mediaCaptureMgr.InitializeAsync();
VideoStream.Source = mediaCaptureMgr;
await mediaCaptureMgr.StartPreviewAsync();
previewStarted = true;
ShowSettings.Visibility = Visibility.Visible;
StartPreview.IsEnabled = false;
}
}
else
{
rootPage.NotifyUser("A webcam is required to run this sample.", NotifyType.ErrorMessage);
}
}
catch (Exception ex)
{
mediaCaptureMgr = null;
rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage);
}
}
示例2: OnNavigatedTo
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
Status.Text = "Status: " + "App started";
//compass
var compass = Windows.Devices.Sensors.Compass.GetDefault();
compass.ReportInterval = 10;
//compass.ReadingChanged += compass_ReadingChanged;
Status.Text = "Status: " + "Compass started";
//geo
var gloc = new Geolocator();
gloc.GetGeopositionAsync();
gloc.ReportInterval = 60000;
gloc.PositionChanged += gloc_PositionChanged;
Status.Text = "Status: " + "Geo started";
//Accelerometer
var aclom = Accelerometer.GetDefault();
aclom.ReportInterval = 1;
aclom.ReadingChanged += aclom_ReadingChanged;
//foursquare
await GetEstablishmentsfromWed();
//camera
var mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
CaptureElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
Status.Text = "Status: " + "Camera feed running";
}
示例3: Grid_Loaded
private async void Grid_Loaded(object sender, RoutedEventArgs e)
{
var camera = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture)).FirstOrDefault();
if (camera != null)
{
mediaCapture = new MediaCapture();
var settings = new MediaCaptureInitializationSettings() { VideoDeviceId = camera.Id };
await mediaCapture.InitializeAsync(settings);
displayRequest.RequestActive();
VideoPreview.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
memStream = new InMemoryRandomAccessStream();
MediaEncodingProfile mediaEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
await mediaCapture.StartRecordToStreamAsync(mediaEncodingProfile, memStream);
}
//video = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Video);
//if (video!=null)
//{
// MediaClip mediaClip = await MediaClip.CreateFromFileAsync(video);
// mediaComposition.Clips.Add(mediaClip);
// mediaStreamSource = mediaComposition.GeneratePreviewMediaStreamSource(600, 600);
// VideoPreview.SetMediaStreamSource(mediaStreamSource);
//}
//FFMPEGHelper.RTMPEncoder encoder = new FFMPEGHelper.RTMPEncoder();
//encoder.Initialize("rtmp://youtube.co");
}
示例4: MainPage_Loaded
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
mediaCapture = new MediaCapture();
DeviceInformationCollection devices =
await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
// Use the front camera if found one
if (devices == null) return;
DeviceInformation info = devices[0];
foreach (var devInfo in devices)
{
if (devInfo.Name.ToLowerInvariant().Contains("front"))
{
info = devInfo;
frontCam = true;
continue;
}
}
await mediaCapture.InitializeAsync(
new MediaCaptureInitializationSettings
{
VideoDeviceId = info.Id
});
captureElement.Source = mediaCapture;
captureElement.FlowDirection = frontCam ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
await mediaCapture.StartPreviewAsync();
DisplayInformation displayInfo = DisplayInformation.GetForCurrentView();
displayInfo.OrientationChanged += DisplayInfo_OrientationChanged;
DisplayInfo_OrientationChanged(displayInfo, null);
}
示例5: OnNavigatedTo
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
if (_mediaCapture == null)
{
// Attempt to get te back camera if one is available, but use any camera device if not
var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(
x => x.EnclosureLocation != null & x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
var cameraDevice = desiredDevice ?? allVideoDevices.FirstOrDefault();
if (cameraDevice == null)
{
// TODO: Implement an error experience for camera-less devices
Debug.Write("No camera device found.");
return;
}
// Create MediaCapture and its setings
_mediaCapture = new MediaCapture();
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
// TODO: Implement an error experience for non-authorized case
await _mediaCapture.InitializeAsync(settings);
// Startin the preview
PreviewControl.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();
}
}
示例6: Loaded
private async void Loaded(object sender, RoutedEventArgs e)
{
MediaCapture capMana = new MediaCapture();
await capMana.InitializeAsync();
Webcam_Logitech.Source = capMana;
await capMana.StartPreviewAsync();
}
示例7: This_Loaded
private async void This_Loaded( object sender, RoutedEventArgs e )
{
try
{
_camera = new MediaCapture();
await _camera.InitializeAsync( new MediaCaptureInitializationSettings
{
VideoDeviceId = ( await GetBackCameraAsync() ).Id,
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview
} );
_camera.VideoDeviceController.FlashControl.Enabled = false;
_camera.SetPreviewRotation( VideoRotation.Clockwise90Degrees );
_camera.SetRecordRotation( VideoRotation.Clockwise90Degrees );
CameraPreview.Source = _camera;
await _camera.StartPreviewAsync();
StartScanning();
}
catch
{
ErrorMessage.Visibility = Visibility.Visible;
}
}
示例8: StartPreviewAsync
public async Task StartPreviewAsync(VideoRotation videoRotation)
{
try
{
if (mediaCapture == null)
{
var cameraDevice = await FindCameraDeviceByPanelAsync(Panel.Back);
mediaCapture = new MediaCapture();
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
await mediaCapture.InitializeAsync(settings);
captureElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
isPreviewing = true;
mediaCapture.SetPreviewRotation(videoRotation);
displayRequest.RequestActive();
}
//DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
}
catch (UnauthorizedAccessException)
{
// This will be thrown if the user denied access to the camera in privacy settings
Debug.WriteLine("The app was denied access to the camera");
}
catch (Exception ex)
{
Debug.WriteLine("MediaCapture initialization failed. {0}", ex.Message);
}
}
示例9: GetCapturePreview
private async Task GetCapturePreview()
{
_capture = new MediaCapture();
var Videodevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
//var rearCamera = Videodevices.FirstOrDefault(item => item.EnclosureLocation != null && item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
var frontCamera = Videodevices.FirstOrDefault(item => item.EnclosureLocation != null && item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);
//TODO: カメラを切り替えられるようにする。
try
{
await _capture.InitializeAsync(new MediaCaptureInitializationSettings
{
VideoDeviceId = frontCamera.Id
});
}
catch (Exception ex)
{
var message = new MessageDialog(ex.Message, "おや?なにかがおかしいようです。");
await message.ShowAsync();
}
capturePreview.Source = _capture;
await _capture.StartPreviewAsync();
}
示例10: Start_Capture_Preview_Click
async private void Start_Capture_Preview_Click(object sender, RoutedEventArgs e)
{
captureManager = new MediaCapture(); //Define MediaCapture object
await captureManager.InitializeAsync(); //Initialize MediaCapture and
capturePreview.Source = captureManager; //Start preiving on CaptureElement
await captureManager.StartPreviewAsync(); //Start camera capturing
}
示例11: Initialize
private async Task Initialize()
{
captureManager = new MediaCapture();
await captureManager.InitializeAsync();
capturePreview.Source = captureManager;
await captureManager.StartPreviewAsync();
}
示例12: IniciaPreviaCapturaFoto
async private void IniciaPreviaCapturaFoto(object sender, RoutedEventArgs e)
{
GerenteCaptura = new Windows.Media.Capture.MediaCapture();
await GerenteCaptura.InitializeAsync();
GerenteCaptura.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
CapturaPrevia.Source = GerenteCaptura;
await GerenteCaptura.StartPreviewAsync();
}
示例13: MainPage_Loaded
async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
CaptureElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
urhoApp = UrhoSurface.Run<UrhoApp>();
urhoApp.CaptureVideo(CaptureFrameAsync);
}
示例14: profilePicture_Tapped
private async void profilePicture_Tapped(object sender, TappedRoutedEventArgs e)
{
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
stackPreview.Visibility = Visibility.Visible;
previewElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
}
示例15: InitCamera
async void InitCamera()
{
mc = new MediaCapture();
var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var camera = cameras[1];
var settings = new MediaCaptureInitializationSettings() { VideoDeviceId = camera.Id };
await mc.InitializeAsync(settings);
ce.Source = mc;
await mc.StartPreviewAsync();
}