本文整理汇总了C#中Windows.Media.Capture.MediaCapture.InitializeAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MediaCapture.InitializeAsync方法的具体用法?C# MediaCapture.InitializeAsync怎么用?C# MediaCapture.InitializeAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Media.Capture.MediaCapture
的用法示例。
在下文中一共展示了MediaCapture.InitializeAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
protected override async void Start()
{
ResourceCache.AutoReloadResources = true;
base.Start();
EnableGestureTapped = true;
busyIndicatorNode = Scene.CreateChild();
busyIndicatorNode.SetScale(0.06f);
busyIndicatorNode.CreateComponent<BusyIndicator>();
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
await mediaCapture.AddVideoEffectAsync(new MrcVideoEffectDefinition(), MediaStreamType.Photo);
await RegisterCortanaCommands(new Dictionary<string, Action> {
{"Describe", () => CaptureAndShowResult(false)},
{"Read this text", () => CaptureAndShowResult(true)},
{"Enable preview", () => EnablePreview(true) },
{"Disable preview", () => EnablePreview(false) },
{"Help", Help }
});
ShowBusyIndicator(true);
await TextToSpeech("Welcome to the Microsoft Cognitive Services sample for HoloLens and UrhoSharp.");
ShowBusyIndicator(false);
inited = true;
}
示例2: 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);
}
示例3: InitCamera_Click
private async void InitCamera_Click(object sender, RoutedEventArgs e)
{
captureManager = new MediaCapture();
await captureManager.InitializeAsync();
// Can only read capabilities after capture device initialized.
VideoDeviceController videoDeviceController = captureManager.VideoDeviceController;
SceneModeControl sceneModeControl = _scene = videoDeviceController.SceneModeControl;
RegionsOfInterestControl regionsOfInterestControl = _regions = videoDeviceController.RegionsOfInterestControl;
bool isFocusSupported = _focus = videoDeviceController.FocusControl.Supported;
bool isIsoSpeedSupported = _iso = videoDeviceController.IsoSpeedControl.Supported;
bool isTorchControlSupported = _torch = videoDeviceController.TorchControl.Supported;
bool isFlashControlSupported = _flash = videoDeviceController.FlashControl.Supported;
if (_scene != null)
{
foreach (CaptureSceneMode mode in _scene.SupportedModes)
{
string t = mode.ToString();
}
}
if (_regions != null)
{
bool autoExposureSupported = _regions.AutoExposureSupported;
bool autoFocusSupported = _regions.AutoFocusSupported;
bool autoWhiteBalanceSupported = _regions.AutoWhiteBalanceSupported;
uint maxRegions = _regions.MaxRegions;
}
}
示例4: 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;
}
}
示例5: Loaded
private async void Loaded(object sender, RoutedEventArgs e)
{
MediaCapture capMana = new MediaCapture();
await capMana.InitializeAsync();
Webcam_Logitech.Source = capMana;
await capMana.StartPreviewAsync();
}
示例6: InitializeCameraAsync
private async Task InitializeCameraAsync()
{
if (mediaCapture == null)
{
// get camera device (back camera preferred)
var cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Back);
if (cameraDevice == null)
{
Debug.WriteLine("no camera device found");
return;
}
// Create MediaCapture and its settings
mediaCapture = new MediaCapture();
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
// Initialize MediaCapture
try
{
await mediaCapture.InitializeAsync(settings);
isInitialized = true;
}
catch (UnauthorizedAccessException)
{
Debug.WriteLine("access to the camera denied");
}
}
}
示例7: Start
public async void Start(int camIndex)
{
// devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (devices.Count > 0)
{
// Using Windows.Media.Capture.MediaCapture APIs to stream from webcam
mediaCaptureMgr = new MediaCapture();
///////////////////////////////////
var captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
captureInitSettings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Video;
captureInitSettings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview;
captureInitSettings.VideoDeviceId = devices[camIndex].Id;
///////////////////////////////////
await mediaCaptureMgr.InitializeAsync(captureInitSettings);
SetResolution();
camCaptureElement.Source = mediaCaptureMgr;
await mediaCaptureMgr.StartPreviewAsync();
}
}
示例8: ReadAsync
/// <summary>
/// Continuously look for a QR code
/// NOTE: this method won't work if recording is enabled ('hey Cortana, start recording' thing).
/// </summary>
public static async Task<string> ReadAsync(CancellationToken token = default(CancellationToken))
{
var mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
await mediaCapture.AddVideoEffectAsync(new MrcVideoEffectDefinition(), MediaStreamType.Photo);
var reader = new BarcodeReader();
reader.Options.TryHarder = false;
while (!token.IsCancellationRequested)
{
var imgFormat = ImageEncodingProperties.CreateJpeg();
using (var ras = new InMemoryRandomAccessStream())
{
await mediaCapture.CapturePhotoToStreamAsync(imgFormat, ras);
var decoder = await BitmapDecoder.CreateAsync(ras);
using (var bmp = await decoder.GetSoftwareBitmapAsync())
{
Result result = await Task.Run(() =>
{
var source = new SoftwareBitmapLuminanceSource(bmp);
return reader.Decode(source);
});
if (!string.IsNullOrEmpty(result?.Text))
return result.Text;
}
}
await Task.Delay(DelayBetweenScans);
}
return null;
}
示例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: InitializeAsync
public async Task InitializeAsync()
{
if (Source != null)
{
return;
}
var deviceInformation = await TryGetDeviceInformationFromPanel(CurrentPanel);
if (deviceInformation == null)
{
return;
}
Source = new MediaCapture();
try
{
await
Source.InitializeAsync(new MediaCaptureInitializationSettings {VideoDeviceId = deviceInformation.Id});
initialized = true;
}
catch
{
return;
}
var properties = Source.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);
configuration.UpdateSupportedVideoSizes(properties);
}
示例11: InitializeAsync
public async Task InitializeAsync()
{
_mediaCapture = new MediaCapture();
await _mediaCapture.InitializeAsync();
_imageEncodingProperties = ImageEncodingProperties.CreateJpeg();
}
示例12: StartDevice_Click
// Click event handler for the "Start Device" button.
private async void StartDevice_Click(object sender, RoutedEventArgs e)
{
try
{
StartDevice.IsEnabled = false;
// Enumerate webcams.
ShowStatusMessage("Enumerating webcams...");
var devInfoCollection = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (devInfoCollection.Count == 0)
{
ShowStatusMessage("No webcams found");
return;
}
// Initialize the MediaCapture object, choosing the first found webcam.
mediaCapture = new Windows.Media.Capture.MediaCapture();
var settings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
settings.VideoDeviceId = devInfoCollection[0].Id;
await mediaCapture.InitializeAsync(settings);
// We can now take photos and enable the grayscale effect.
TakePhoto.IsEnabled = true;
AddRemoveEffect.IsEnabled = true;
ShowStatusMessage("Device initialized successfully");
}
catch (Exception ex)
{
ShowExceptionMessage(ex);
}
}
开发者ID:terryjintry,项目名称:OLSource1,代码行数:33,代码来源:walkthrough--creating-a-windows-store-app-using-wrl-and-media-foundation_8.cs
示例13: RequestMicrophonePermission
public async static Task<bool> RequestMicrophonePermission()
{
try
{
var settings = new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Audio,
MediaCategory = MediaCategory.Speech,
};
var capture = new MediaCapture();
await capture.InitializeAsync(settings);
}
catch (UnauthorizedAccessException)
{
return false;
}
catch (Exception ex)
{
if (ex.HResult == -1072845856)
{
// No Audio Capture devices are present on this system.
}
return false;
}
return true;
}
示例14: Page_Loaded
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
MediaCaptureInitializationSettings set = new MediaCaptureInitializationSettings();
set.StreamingCaptureMode = StreamingCaptureMode.Video;
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync(set);
}
示例15: enumerateCameras
public static async Task<List<DeviceInfo>> enumerateCameras()
{
var deviceInfo = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
List<DeviceInfo> devices = new List<DeviceInfo>();
for (int i = 0; i < deviceInfo.Count; i++)
{
DeviceInfo device = new DeviceInfo();
device.deviceID = deviceInfo[i].Id;
device.deviceInfo = deviceInfo[i];
device.deviceName = deviceInfo[i].Name;
try
{
MediaCaptureInitializationSettings mediaSetting = new MediaCaptureInitializationSettings();
setCaptureSettings(out mediaSetting, device.deviceID);
MediaCapture mCapture = new MediaCapture();
await mCapture.InitializeAsync(mediaSetting);
device.resolutionList = updateResolution(mCapture);
}
catch
{
}
devices.Add(device);
}
return devices;
}