c# - 如何在 Windows 8.1 中捕获高分辨率视频并从中捕获照片。我在尝试时有 UI 跳跃效果

标签 c# windows-8 windows-runtime windows-8.1

我的相机捕获应用程序用于使用在使用 CaptureElement 的 View 中实现的相机拍摄连续照片。当它连续拍摄照片时,用户界面来回移动看起来像是一种跳跃效果。这就是我面临的问题。

使用的代码如下

var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
MediaCaptureInitializationSettings settings=new MediaCaptureInitializationSettings { VideoDeviceId = cameras[0].Id, StreamingCaptureMode = StreamingCaptureMode.Video };
var_mediaCapture = new MediaCapture();
await _mediaCapture.InitializeAsync(settings);
if (null != videoCapture) videoCapture.Source = _mediaCapture;
            await _mediaCapture.StartPreviewAsync();

设置高分辨率

int max = 0;
var resolutions = videoController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
            for (var i = 0; i < resolutions.Count; i++)
            {
                ImageEncodingProperties res = resolutions[i] as ImageEncodingProperties;
                if (null == res) continue;


                if (res.Width * res.Height < max)
                {
                    max = (int)(res.Width * res.Height);
                    _imageEncodingProperties = res;
                }
            }

     await videoController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, _imageEncodingProperties);

并使用

从视频帧中捕获照片
    using (var photoStream = new InMemoryRandomAccessStream())
                {                        
                    await _mediaCapture.CapturePhotoToStreamAsync(_imageEncodingProperties, photoStream);
                    await photoStream.FlushAsync(); 
                }

我通过设置不同的视频分辨率来测试捕获。

var videoController = _mediaCapture.VideoDeviceController;

首先,我为 videoController 设置了默认的 preview 分辨率 [640x480],捕获过程没有任何问题。之后我通过在 Surface tablet 中设置 High resolution [1200x800] 来检查它,在这种情况下,相框会出现在视频控件上一会儿,并且它的每一侧都有一些小宽度.感觉就像在相机 View 中放大/缩小效果 [back n forward jumping]。

在 Windows 8.1 中为视频媒体元素视频 Controller 设置高分辨率时,有人遇到过这个问题吗?如果有人能解释它的原因,那就太好了。

谢谢

编辑: 我分析了一下情况,发现了以下几点

有许多可用的分辨率 640 x 360、1280x720、1280x800、640x480 等

而且我发现在宽高比为1.777778的分辨率下根本不会出现这个问题。 rato 小于 1.777 的所有其他分辨率都有问题。

也就是说,640x360、1280x720等分辨率不存在这个问题,另外两个有跳变效果。我认为最后两个的比率分别为 1.6 和 1.33。

我还检查了默认相机应用并通过设置 1280x800 分辨率拍摄照片,我看到窗口中相机元素的两侧都有黑色边框。

结论:

The issue was with the aspect ratio. When i set High resolution [1280x800] from the available camera resolutions which is not maintaining the surface device's aspect ratio [1366x768], so that the Image is trying to fit in to the screen and an jumping effect felt by the user. So i set the Highest resolution which maintains the device aspect ratio , which is 1280x720 and the problem solved.

最佳答案

Actually the issue was with the aspect ratio. When i set High resolution [1280x800] from the available camera resolutions which is not maintaining the surface device's aspect ratio [1366x768], so that the Image is trying to fit in to the screen and an jumping effect felt by the user. So i set the Highest resolution which maintains the device aspect ratio , which is 1280x720 and the problem solved.

关于c# - 如何在 Windows 8.1 中捕获高分辨率视频并从中捕获照片。我在尝试时有 UI 跳跃效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23808547/

相关文章:

xaml - 在 Windows 8 应用商店应用程序中重新使用 XAML 路径

c# - 使用带有目标对象信息的 MEF 注入(inject)对象

c# - 如何在 Entity Framework 6 中延迟加载关系?

c# datatable 无法更新。数据库或对象是只读的

windows - 从本地源安装 Windows 8 应用程序?

c# - HtmlAgilityPack - 删除集合中的所有节点

c# - 将 CheckBox 列添加到具有持久性的 GridView

Windows 8 环绕面板

xaml - 本地化 x :String

audio - Win RT 中的音乐效果