【问题标题】:Windows phone 8.1 camera preview black edge on rotationWindows phone 8.1 相机预览旋转时出现黑边
【发布时间】:2016-06-07 07:01:39
【问题描述】:

我在 windows phone 8.1 上使用视频预览来拍照。没有旋转,预览没有黑边。旋转 90 度后,捕获元素上出现条纹。

这是我的屏幕截图和 XAML,c# 代码。

XAML

CaptureElement x:Name="capturePreview" Stretch="UniformToFill" Margin="27,158,10,10" Grid.ColumnSpan="2" />

C#

    public async void preview()
    {
        DeviceInformationCollection webcamList = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

        DeviceInformation backWebcam = (from webcam in webcamList
                                        where webcam.EnclosureLocation != null
                                        && webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back
                                        select webcam).FirstOrDefault();
         newCapture = new MediaCapture();          
        await newCapture.InitializeAsync(new MediaCaptureInitializationSettings
        {
            VideoDeviceId = backWebcam.Id,
            AudioDeviceId = "",
            StreamingCaptureMode = StreamingCaptureMode.Video,
            PhotoCaptureSource = PhotoCaptureSource.VideoPreview
        });                 
        await newCapture.StartPreviewAsync();
        newCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
    }

图片旋转

无旋转

【问题讨论】:

    标签: c# xaml camera windows-phone-8.1


    【解决方案1】:

    不要使用 mediaCapture.SetPreviewRotation,因为它会为您的流添加信箱。而是使用来自Camera Starter Kit UWP sampleMicrosoft GitHub repository 的SetPreviewRotationAsync 方法。如果您仔细观察它,您会更好地了解如何处理相机的旋转。

    主要是这样的:

        // Rotation metadata to apply to the preview stream and recorded videos (MF_MT_VIDEO_ROTATION)
        // Reference: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868174.aspx
        private static readonly Guid RotationKey = new Guid("C380465D-2271-428C-9B83-ECEA3B4A85C1");
    
        /// <summary>
        /// Gets the current orientation of the UI in relation to the device (when AutoRotationPreferences cannot be honored) and applies a corrective rotation to the preview
        /// </summary>
        private async Task SetPreviewRotationAsync(int rotationDegrees)
        {
            // Add rotation metadata to the preview stream to make sure the aspect ratio / dimensions match when rendering and getting preview frames
            var props = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview);
            props.Properties.Add(RotationKey, rotationDegrees);
            await _mediaCapture.SetEncodingPropertiesAsync(MediaStreamType.VideoPreview, props, null);
        }
    

    但这只是代码的一部分。您应该查看the full file(如果不是完整示例)以更好地了解它的工作原理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      相关资源
      最近更新 更多