[英]Issue with aspect ratio / zoom level changing when using MediaCapture?
I am using MediaCapture along with CapturePreview to create a preview stream on a Surface Pro tablet. 我正在使用MediaCapture和CapturePreview在Surface Pro平板电脑上创建预览流。 I am taking photos periodically with a timer using
我使用定时器定期拍照
CapturePhotoToStreamAsync()
Whenever a photo is taken though, the preview stream zooms out slightly as if it is changing the resolution or aspect ratio or something similar. 但是,无论何时拍摄照片,预览流都会稍微缩小,就好像它在更改分辨率或宽高比或类似内容一样。
I found this issue , which sounds exactly the same, but I can't seem to resolve it regardless of the resolutions set. 我发现了这个问题 ,听起来似乎完全一样,但是无论设置哪种分辨率,我似乎都无法解决。
This is the bit of code I have to grab Bitmap
objects from the stream: 这是我必须从流中获取
Bitmap
对象的代码:
using (var randomAccessStream = new InMemoryRandomAccessStream())
{
await mediaCap.CapturePhotoToStreamAsync(imageProps, randomAccessStream);
randomAccessStream.Seek(0);
using (var ioStream = randomAccessStream.AsStream())
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = ioStream;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
bitmapImage.Freeze();
}
}
imageProps
is being set to 1280x720, the same resolution as the preview object. imageProps
设置为1280x720,与预览对象的分辨率相同。 This wouldn't be a huge issue if it only happened occasionally, but I need to grab frames frequently (multiple times per second), and it looks very jarring. 如果它只是偶尔发生,那么这将不是一个大问题,但是我需要频繁抓取帧(每秒多次),并且看起来非常刺耳。
Edit: 编辑:
Something to note is that the issue only occurs on the mentioned Surface Pro tablet (2736x1824 @200%), it doesn't appear to occur on a 1920x1080 screen. 需要注意的是,该问题仅发生在提到的Surface Pro平板电脑(2736x1824 @ 200%)上,而在1920x1080屏幕上似乎没有发生。
The solution I ended up finding was this change: 我最终找到的解决方案是此更改:
From: 从:
await _mediaCaptureObject.InitializeAsync(new MediaCaptureInitializationSettings
{
VideoDeviceId = deviceList?.FirstOrDefault(x => x.Name.Contains("Camera Name"))?.Id,
StreamingCaptureMode = StreamingCaptureMode.Video
});
To: 至:
await _mediaCaptureObject.InitializeAsync(new MediaCaptureInitializationSettings
{
VideoDeviceId = deviceList?.FirstOrDefault(x => x.Name.Contains("Camera Name"))?.Id,
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview
});
This doesn't really explain the issue I was seeing, since I was setting the ImageEncodingProperties
to the same resolution as the stream when capturing the photo. 这并不能真正解释我所遇到的问题,因为我在捕获照片时将
ImageEncodingProperties
设置为与流相同的分辨率。 Anyway, the default PhotoCaptureSource
is Auto
, which must've been using the Photo
mode instead of VideoPreview
. 无论如何,默认的
PhotoCaptureSource
是Auto
,它必须一直使用Photo
模式而不是VideoPreview
。 Once I changed this, the issue stopped appearing. 更改此设置后,问题不再出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.