2016-04-07 11 views

Antwort

0

Wenn Sie das CameraStarterKit Beispiel aus der Microsoft GitHub repository betrachten, erhalten Sie eine viel bessere Idee für die Drehung der Kamera. Es zielt auf Windows 10 ab, aber ein großer Teil des Codes sollte wieder auf 8.1 portierbar sein.

Vor allem kommt es darauf an, diese:

// Receive notifications about rotation of the device and UI and apply any necessary rotation to the preview stream and UI controls  
    private readonly DisplayInformation _displayInformation = DisplayInformation.GetForCurrentView(); 
    private readonly SimpleOrientationSensor _orientationSensor = SimpleOrientationSensor.GetDefault(); 
    private SimpleOrientation _deviceOrientation = SimpleOrientation.NotRotated; 
    private DisplayOrientations _displayOrientation = DisplayOrientations.Portrait; 

    // 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() 
    { 
     // Only need to update the orientation if the camera is mounted on the device 
     if (_externalCamera) return; 

     // Calculate which way and how far to rotate the preview 
     int rotationDegrees = ConvertDisplayOrientationToDegrees(_displayOrientation); 

     // The rotation direction needs to be inverted if the preview is being mirrored 
     if (_mirroringPreview) 
     { 
      rotationDegrees = (360 - rotationDegrees) % 360; 
     } 

     // 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); 
    } 

    /// <summary> 
    /// Registers event handlers for hardware buttons and orientation sensors, and performs an initial update of the UI rotation 
    /// </summary> 
    private void RegisterEventHandlers() 
    { 
     // If there is an orientation sensor present on the device, register for notifications 
     if (_orientationSensor != null) 
     { 
      _orientationSensor.OrientationChanged += OrientationSensor_OrientationChanged; 

      // Update orientation of buttons with the current orientation 
      UpdateButtonOrientation(); 
     } 

     _displayInformation.OrientationChanged += DisplayInformation_OrientationChanged; 
    } 

Aber das ist nur ein Teil des Codes. Sie sollten einen Blick auf werfen (wenn nicht das vollständige Beispiel), um ein besseres Verständnis davon zu bekommen, wie es funktioniert.