1

我試圖旋轉CameraPreviewImageSource使它看起來(只)在人像模式:旋轉CamerePreviewImageSource

private async Task InitializeAsync() 
    { 
     this.cameraPreviewImageSource = new CameraPreviewImageSource(); 

     DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture); 
     String backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back).Id; 
     await cameraPreviewImageSource.InitializeAsync(backCameraId); 

     VideoEncodingProperties properties = await this.cameraPreviewImageSource.StartPreviewAsync(); 

     double width = 1280; 
     double height = 720; 

     this.writeableBitmap = new WriteableBitmap((int)width, (int)height); 
     this.capturePreview.Source = this.writeableBitmap; 

     this.writeableBitmapRenderer = new WriteableBitmapRenderer(); 
     this.jpegRenderer = new JpegRenderer(); 

     this.cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable; 
    } 

我也試過在XAML文件,但大部分的時間,結果是怪異(像90%的圖片被隱藏):

<Image x:Name="capturePreview" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="3" Width="auto" Height="auto" Canvas.ZIndex="0" > 
    <Image.RenderTransform> 
     <CompositeTransform CenterX="0.5" CenterY="0.5" Rotation="90" /> 
    </Image.RenderTransform> 
</Image> 

任何想法?

+0

你是什麼意思使它只出現在肖像模式?你的意思是說,無論他們以哪種方式轉動它,它總是以縱向模式出現?或者你的意思是不可見,除非在肖像模式? – 2014-11-04 17:46:47

+0

「無論他們以哪種方式打開它,它總是看起來好像是在肖像模式下」 – 2014-11-04 18:08:04

回答

2

嘗試這個開關,寬度和高度,並添加一個RotationFilter與設置爲90旋轉也設置設備的方向肖像。 如果你想在應用程序的其餘部分支持另一個方向,只需設置方向開航到/開航從

private async Task InitializeAsync() 
{ 
    this.cameraPreviewImageSource = new CameraPreviewImageSource(); 

    DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture); 
    String backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back).Id; 
    await cameraPreviewImageSource.InitializeAsync(backCameraId); 

    VideoEncodingProperties properties = await this.cameraPreviewImageSource.StartPreviewAsync(); 

    double width = 1280; 
    double height = 720; 

    this.writeableBitmap = new WriteableBitmap((int)height, (int)width); 
    this.capturePreview.Source = this.writeableBitmap; 
    var effect = new FilterEffect(m_cameraPreviewImageSource); 
    effect.Filters = new IFilter[] { new RotationFilter(90) }; 

    this.writeableBitmapRenderer = new WriteableBitmapRenderer(effect); 
    this.jpegRenderer = new JpegRenderer(); 

    this.cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable; 
} 


protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    m_displayOrientations = DisplayInformation.AutoRotationPreferences; 
    DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait; 
    NavigationHelper.OnNavigatedTo(e); 
} 

protected override void OnNavigatedFrom(NavigationEventArgs e) 
{ 
    DisplayInformation.AutoRotationPreferences = m_displayOrientations; 
    NavigationHelper.OnNavigatedFrom(e); 
} 
+0

抱歉,遲到了,我昨天做了一些非常相似的事情,它的工作,謝謝你的支持。 – 2014-11-12 18:31:28

0

由於您正在使用諾基亞成像SDK來實現此目的,您是否嘗試在渲染鏈中添加RotateFilter並在需要時旋轉它?

您的鏈接將是:CameraPreviewSource - > FilterEffect [rotateFilter] - > WriteableBitmapRenderer。

+0

對不起,遲到的回覆我跟着那昨天,它的工作。謝謝 – 2014-11-12 18:30:10