private async void InitializeMediaCapture() { _capturedSequence = new List <IRandomAccessStream>(); _mediaCapture = new MediaCapture(); var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); var backCamera = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back); await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Video, PhotoCaptureSource = PhotoCaptureSource.Auto, AudioDeviceId = string.Empty, VideoDeviceId = backCamera.Id }); captureElement.Source = _mediaCapture; await _mediaCapture.StartPreviewAsync(); var format = ImageEncodingProperties.CreateJpeg(); format.Width = 640; format.Height = 480; _lowLagPhotoSequenceCapture = await _mediaCapture.PrepareLowLagPhotoSequenceCaptureAsync(format); _lowLagPhotoSequenceCapture.PhotoCaptured += OnPhotoCaptured; }
public static async void CaptureMorePhoto(Action <uint, uint, PhotoCapturedEventArgs> executeAction, Action overAction) { if (MainCamera.VideoDeviceController.LowLagPhotoSequence.Supported == false) { overAction(); return; } var captureTime = DateTime.Now; var pastFrame = 10u; var maxFrame = MainCamera.VideoDeviceController.LowLagPhotoSequence.MaxPastPhotos; if (pastFrame > maxFrame) { pastFrame = maxFrame; } MainCamera.VideoDeviceController.LowLagPhotoSequence.ThumbnailEnabled = true; MainCamera.VideoDeviceController.LowLagPhotoSequence.DesiredThumbnailSize = 300; MainCamera.VideoDeviceController.LowLagPhotoSequence.PhotosPerSecondLimit = 4; MainCamera.VideoDeviceController.LowLagPhotoSequence.PastPhotoLimit = pastFrame; var photoCapture = await MainCamera.PrepareLowLagPhotoSequenceCaptureAsync(ImageEncodingProperties.CreateJpeg()); var nowIndex = 1u; photoCapture.PhotoCaptured += new Windows.Foundation.TypedEventHandler <LowLagPhotoSequenceCapture, PhotoCapturedEventArgs>(async(ds, de) => { if (nowIndex > pastFrame) { return; } executeAction(nowIndex, pastFrame, de); //处理索引 if (nowIndex == pastFrame) { await ds.StopAsync(); await ds.FinishAsync(); overAction(); } nowIndex++; }); await photoCapture.StartAsync(); }