UWP 相机预览:"No suitable transform was found to encode or decode"
UWP Camera preview: "No suitable transform was found to encode or decode"
我正在 UWP 中预览带有 CaptureElement 的相机。但为什么在使用某些分辨率时会出现错误:"No suitable transform was found to encode or decode"?使用网络摄像头时会发生
我在使用此方法时没有收到错误消息:mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(...)。但是如果我使用这种方法,捕获元素不会缩放到我想要的分辨率(捕获元素将它的 strech 属性设置为 none 因为我不想质量损失)
try
{
MediaCaptureInitializationSettings mediacapturesettings = new MediaCaptureInitializationSettings { VideoDeviceId = DeviceInfo.Id };
await mediacapture.InitializeAsync(mediacapturesettings);
}
catch (Exception exception)
{
var dialog = new MessageDialog(exception.Message);
await dialog.ShowAsync();
}
captureelement.Source = mediacapture;
captureelement.FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight;
await mediacapture.StartPreviewAsync();
// await mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, Resolution.EncodingProperties);
await mediacapture.SetEncodingPropertiesAsync(MediaStreamType.VideoPreview, Resolution.EncodingProperties,null);
VideoRotation currentrotation = Rotation;
mediacapture.SetPreviewRotation(currentrotation);
I don't get the error when i use this method: mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(...). but if i use this method, the captureelement doesn't get scaled to the resolution i want .
It only happens the first time i callstartpreview().
我已经在内部咨询并得到了回复。这个问题可能与图形驱动程序有关。您的图形驱动程序可能要求您的相机设备预览在您调用 MediaCapture.SetEncodingPropertiesAsync
之前处于 运行 状态,因此您收到此错误并且仅在第一次收到。
i want to know the difference between the two methods.
区别:
- MediaCapture.SetEncodingPropertiesAsync 在相机水槽上设置 属性。您可以在这里设置相机不支持的分辨率和旋转,然后编码器将工作以转换为所需的格式。
- MediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync 在源上设置属性。您只能设置相机支持的配置。
因此预览 window 的大小由 Xaml CaptureElement
控制。如果你正在使用VideoDeviceController.SetMediaStreamPropertiesAsync
并且想要调整预览window的大小,你只能设置Stretch="UniformToFill"
让预览window填充父元素。
我正在 UWP 中预览带有 CaptureElement 的相机。但为什么在使用某些分辨率时会出现错误:"No suitable transform was found to encode or decode"?使用网络摄像头时会发生
我在使用此方法时没有收到错误消息:mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(...)。但是如果我使用这种方法,捕获元素不会缩放到我想要的分辨率(捕获元素将它的 strech 属性设置为 none 因为我不想质量损失)
try
{
MediaCaptureInitializationSettings mediacapturesettings = new MediaCaptureInitializationSettings { VideoDeviceId = DeviceInfo.Id };
await mediacapture.InitializeAsync(mediacapturesettings);
}
catch (Exception exception)
{
var dialog = new MessageDialog(exception.Message);
await dialog.ShowAsync();
}
captureelement.Source = mediacapture;
captureelement.FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight;
await mediacapture.StartPreviewAsync();
// await mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, Resolution.EncodingProperties);
await mediacapture.SetEncodingPropertiesAsync(MediaStreamType.VideoPreview, Resolution.EncodingProperties,null);
VideoRotation currentrotation = Rotation;
mediacapture.SetPreviewRotation(currentrotation);
I don't get the error when i use this method: mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(...). but if i use this method, the captureelement doesn't get scaled to the resolution i want .
It only happens the first time i callstartpreview().
我已经在内部咨询并得到了回复。这个问题可能与图形驱动程序有关。您的图形驱动程序可能要求您的相机设备预览在您调用 MediaCapture.SetEncodingPropertiesAsync
之前处于 运行 状态,因此您收到此错误并且仅在第一次收到。
i want to know the difference between the two methods.
区别:
- MediaCapture.SetEncodingPropertiesAsync 在相机水槽上设置 属性。您可以在这里设置相机不支持的分辨率和旋转,然后编码器将工作以转换为所需的格式。
- MediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync 在源上设置属性。您只能设置相机支持的配置。
因此预览 window 的大小由 Xaml CaptureElement
控制。如果你正在使用VideoDeviceController.SetMediaStreamPropertiesAsync
并且想要调整预览window的大小,你只能设置Stretch="UniformToFill"
让预览window填充父元素。