• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Capture.MediaCapture类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Windows.Media.Capture.MediaCapture的典型用法代码示例。如果您正苦于以下问题:C# MediaCapture类的具体用法?C# MediaCapture怎么用?C# MediaCapture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MediaCapture类属于Windows.Media.Capture命名空间,在下文中一共展示了MediaCapture类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: 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


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


示例3: InitializePreview

        public async Task InitializePreview(CaptureElement captureElement)
        {
            captureManager = new MediaCapture();

            var cameraID = await GetCameraID(Panel.Back);

            if (cameraID == null)
            {
                return;
            }

            await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
            {
                StreamingCaptureMode = StreamingCaptureMode.Video,
                PhotoCaptureSource = PhotoCaptureSource.Photo,
                AudioDeviceId = string.Empty,
                VideoDeviceId = cameraID.Id
            });

            await
                captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo,
                    maxResolution());

            captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);

            StartPreview(captureElement);
        }
开发者ID:iot-alex,项目名称:virtual-shields-universal,代码行数:27,代码来源:Camera.cs


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


示例5: ViewfinderPage

 public ViewfinderPage()
 {
     InitializeComponent();
     _navigationHelper = new NavigationHelper(this);
     _photoCaptureManager = new MediaCapture();
     _dataContext = FilterEffects.DataContext.Instance;
 }
开发者ID:JuannyWang,项目名称:filter-effects,代码行数:7,代码来源:ViewfinderPage.xaml.cs


示例6: 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 
 }
开发者ID:trilok567,项目名称:Windows-Phone,代码行数:7,代码来源:MainPage.xaml.cs


示例7: 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");
        }
开发者ID:krishnan-unni,项目名称:FFMPEGHelper,代码行数:28,代码来源:VideoProcessing.xaml.cs


示例8: Reader

 /// <summary>
 /// Initializes a new instance of the <see cref="Reader" /> class.
 /// </summary>
 /// <param name="capture">MediaCapture instance.</param>
 /// <param name="width">Capture frame width.</param>
 /// <param name="height">Capture frame height.</param>
 public Reader(MediaCapture capture, uint width, uint height)
 {
     this.capture = capture;
     this.encodingProps = new ImageEncodingProperties { Subtype = "BMP", Width = width, Height = height};
     this.barcodeFound = false;
     this.cancelSearch = new CancellationTokenSource();
 }
开发者ID:CareWB,项目名称:WeX5,代码行数:13,代码来源:Reader.cs


示例9: 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


示例10: 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


示例11: 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


示例12: OnNavigatedTo

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            captureManager = new MediaCapture();
            reader = new BarcodeReader();

            PreviewCameraFeed();
        }
开发者ID:mbmccormick,项目名称:Authenticator,代码行数:7,代码来源:ScanPage.xaml.cs


示例13: 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


示例14: 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


示例15: cameraCapture_Failed

 private async void cameraCapture_Failed(MediaCapture sender, MediaCaptureFailedEventArgs errorEventArgs)
 {
     // It's safest to return this back onto the UI thread to show the message dialog.
     MessageDialog dialog = new MessageDialog(errorEventArgs.Message);
     await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
         async () => { await dialog.ShowAsync(); });
 }
开发者ID:Ronacs,项目名称:WinDevCamp,代码行数:7,代码来源:MainPage.xaml.cs


示例16: 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


示例17: 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);
     }
 }
开发者ID:builttoroam,项目名称:BuildIt,代码行数:28,代码来源:CameraFeedUtility.cs


示例18: 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


示例19: RequestMicrophoneCapture

        /// <summary>
        /// On desktop/tablet systems, users are prompted to give permission to use capture devices on a 
        /// per-app basis. Along with declaring the microphone DeviceCapability in the package manifest,
        /// this method tests the privacy setting for microphone access for this application.
        /// Note that this only checks the Settings->Privacy->Microphone setting, it does not handle
        /// the Cortana/Dictation privacy check, however (Under Settings->Privacy->Speech, Inking and Typing).
        /// 
        /// Developers should ideally perform a check like this every time their app gains focus, in order to 
        /// check if the user has changed the setting while the app was suspended or not in focus.
        /// </summary>
        /// <returns>true if the microphone can be accessed without any permissions problems.</returns>
        /// 
        public async static Task<bool> RequestMicrophoneCapture()
        {
            try
            {
                // Request access to the microphone only, to limit the number of capabilities we need
                // to request in the package manifest.
                MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
                settings.MediaCategory = MediaCategory.Speech;
                MediaCapture capture = new MediaCapture();
                await capture.InitializeAsync(settings);
            }
            catch (UnauthorizedAccessException)
            {   // The user has turned off access to the microphone. If this occurs, we should show an error, or disable
                // functionality within the app to ensure that further exceptions aren't generated when 
                // recognition is attempted.
                return false;
            }
            catch (Exception exception)
            {
                // This can be replicated by using remote desktop to a system, but not redirecting the microphone input.
                // Can also occur if using the virtual machine console tool to access a VM instead of using remote desktop.
                if (exception.HResult == NoCaptureDevicesHResult)
                {
                    return false;
                }
                else
                {
                    throw;
                }

            }
            return true;
        }
开发者ID:intui,项目名称:SlideProjector,代码行数:46,代码来源:AudioCapturePermissions.cs


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Capture.MediaCaptureInitializationSettings类代码示例发布时间:2022-05-26
下一篇:
C# Foundation.Size类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap