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


C# Capture.MediaCapture类代码示例

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


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


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