当前位置: 首页>>代码示例>>C#>>正文


C# MediaCapture.InitializeAsync方法代码示例

本文整理汇总了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;
		}
开发者ID:xamarin,项目名称:urho-samples,代码行数:28,代码来源:Program.cs

示例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);
        }
开发者ID:GoreMaria,项目名称:LondonHack2,代码行数:35,代码来源:MainPage.xaml.cs

示例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;
            }
        }
开发者ID:noriike,项目名称:xaml-106136,代码行数:33,代码来源:MainPage.xaml.cs

示例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;
            }
        }
开发者ID:ValentinMinder,项目名称:pocketcampus,代码行数:25,代码来源:CodeScanView.xaml.cs

示例5: Loaded

 private async void Loaded(object sender, RoutedEventArgs e)
 {
     MediaCapture capMana = new MediaCapture();
     await capMana.InitializeAsync();
     Webcam_Logitech.Source = capMana;
     await capMana.StartPreviewAsync();
 }
开发者ID:spqa,项目名称:WSAD2,代码行数:7,代码来源:Webcam.xaml.cs

示例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");
                }
            }
        }
开发者ID:UWPanda,项目名称:BemeRecorder,代码行数:30,代码来源:MainPage.xaml.cs

示例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();

            }
        }
开发者ID:valeryjacobs,项目名称:TheEyeOnThings,代码行数:25,代码来源:MainPage.xaml.cs

示例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;
		}
开发者ID:xamarin,项目名称:urho-samples,代码行数:35,代码来源:QrCodeReader.cs

示例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();
        }
开发者ID:Bongorian,项目名称:MSPlatoon1,代码行数:27,代码来源:InitPage02.xaml.cs

示例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);
        }
开发者ID:rachwal,项目名称:RTM-Windows-10-Client,代码行数:29,代码来源:CameraController.cs

示例11: InitializeAsync

        public async Task InitializeAsync()
        {
            _mediaCapture = new MediaCapture();
            await _mediaCapture.InitializeAsync();

            _imageEncodingProperties = ImageEncodingProperties.CreateJpeg();
        }
开发者ID:elcalado,项目名称:showmelove,代码行数:7,代码来源:ImageCapture.cs

示例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;
 }
开发者ID:haroldma,项目名称:Audiotica,代码行数:26,代码来源:AudioUtils.cs

示例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);
 }
开发者ID:hoai,项目名称:Project_Oxford_Emotions_UWP,代码行数:7,代码来源:MainPage.xaml.cs

示例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;
        }
开发者ID:yjlintw,项目名称:YJToolkit,代码行数:28,代码来源:CameraUtil.cs


注:本文中的Windows.Media.Capture.MediaCapture.InitializeAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。