2016-06-07 58 views
1

我在Windows Phone 8.1上使用視頻預覽來拍照。沒有旋轉,預覽沒有黑邊邊緣。捕捉元件上出現90度旋轉條紋後。Windows phone 8.1相機預覽黑邊旋轉

這裏是我的截圖和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); 
    } 

圖片輪換

enter image description here

不旋轉

enter image description here

回答

0

不要使用mediaCapture.SetPreviewRotation,因爲它會添加加框您的信息流。請改用Microsoft GitHub repositoryCamera Starter Kit UWP sample中的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(如果不是全部示例),以更好地理解它是如何工作的。

+0

這很棒!謝謝你的時間邁克。 –