Capture元素在Windows Phone 8.1中显示90度预览

时间:2016-05-15 11:45:59

标签: windows-phone-8.1 winrt-xaml

我的xaml中有以下捕获元素代码。

  <CaptureElement Width="400" Height="400" x:Name="cameraCapture" Stretch="UniformToFill" Margin="0,0,0,40">
  </CaptureElement>

我的页面已加载

   private async void MainPage_Loaded(object sender, RoutedEventArgs e)
    {

        await captureManager.InitializeAsync();
        cameraCapture.Source = captureManager;
        await captureManager.StartPreviewAsync();
    }

在预览中显示旋转的图像 enter image description here

如果我将旋转设置为预览而不是在视图中它工作正常但保存的图像仍然旋转到90度。我怎样才能解决这个问题?

   captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);

1 个答案:

答案 0 :(得分:1)

致电CapturePhotoToStreamAsync后,您应该在流媒体上应用这些内容:

 //create decoder and encoder
 BitmapDecoder dec = await BitmapDecoder.CreateAsync(imageStream);
 BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(imageStream, dec);

 //roate the image
 enc.BitmapTransform.Rotation = BitmapRotation.Clockwise90Degrees;

 //write changes to the image stream
 await enc.FlushAsync();

这只是一个片段,但我想你明白了。 有关完整代码示例,请查看此处:https://dzone.com/articles/how-capture-photo-your-windows-0