2012-04-19 28 views
6

我試圖將視頻方向與手機方向相匹配,但我遇到了實施此解決方案的問題。我的xaml頁面設置爲PortraitOrLandscape,無論手機的方向如何,我都希望視頻筆正面朝上。加上定向if語句更改爲onOrentationChanged事件之前,下面的情況是發生視頻方向與手機方向不匹配

電話:景觀左的VideoBrush:正面朝上

電話:人像,的VideoBrush,旋轉-90順時針

電話:風景右,的VideoBrush,旋轉,順時針-180

XAML

<Rectangle x:Name="videoRectangle" Margin="0,0,0,0"> 
      <Rectangle.Fill> 
       <VideoBrush x:Name="viewfinderBrush" AlignmentX="Left" AlignmentY="Top" Stretch="UniformToFill"> 
        <VideoBrush.RelativeTransform> 
         <CompositeTransform x:Name="viewfinderTransform" 
              CenterX="0.5" CenterY="0.5"/> 
        </VideoBrush.RelativeTransform> 
       </VideoBrush>      
      </Rectangle.Fill> 
     </Rectangle> 

XAML.CS

protected override void OnOrientationChanged(OrientationChangedEventArgs e) 
    { 
     base.OnOrientationChanged(e); 

     if (e.Orientation == PageOrientation.LandscapeLeft) 
     {    //do nothing 
         //The videobrush orientation is currently right side up 
     } 
     if (e.Orientation == PageOrientation.Portrait) 
     { 
      //the videobrush is currently rotated 90 degrees counter clockwise 
      this.viewfinderTransform.Rotation = this.camera.Orientation + 90.0; 
     } 
     if (e.Orientation == PageOrientation.LandscapeRight) 
     { 
      //the videobrush is currently rotated 180 degrees counter clockwise 
      this.viewfinderTransform.Rotation = this.camera.Orientation + 180; 
     } 
    } 

並添加if語句後,視頻刷的方向變得更瘋狂。我究竟做錯了什麼?無論手機的方向如何,我只是希望將視頻筆的方向設置爲正面。

+0

除了你展示的內容外,還有其他的事情正在進行。 XAML(沒有codebehind)按照您在模擬器和手機上的預期工作。雖然,我不確定你爲什麼使用'VisualBrush'繪製一個'Rectangle',或者提供一個以UniformToFill對象爲中心的變換。 – 2012-04-19 04:05:12

+1

this.viewfinderTransform.Rotation = this.camera.Orientation; 這不工作? – TutuGeorge 2012-04-19 05:23:49

+0

@Ritch我只是引用了我發現的有關使用視頻畫一個對象(矩形)的幾個MSDN源。在我的情況下,UniformToFill效果最好,因爲在縱向和橫向之間旋轉我的手機時,我不希望寬度和高度有任何差異(我注意到這樣做時視頻刷圖像被拉伸和擠壓),UniformToFill在整個設備的旋轉。 – Matthew 2012-04-19 07:39:52

回答

6

我用一個簡單的開關/箱正常旋轉的VideoBrush:

protected override void OnOrientationChanged(OrientationChangedEventArgs e) 
{ 
    base.OnOrientationChanged(e); 
    switch (e.Orientation) 
    { 
    case PageOrientation.Landscape: 
    case PageOrientation.LandscapeLeft: 
     videoBrushTransform.Rotation = 0; 
     break; 
    case PageOrientation.LandscapeRight: 
     videoBrushTransform.Rotation = 180; 
     break; 
    case PageOrientation.Portrait: 
    case PageOrientation.PortraitUp: 
     videoBrushTransform.Rotation = 90; 
     break; 
    case PageOrientation.PortraitDown: 
     videoBrushTransform.Rotation = 270; 
     break; 
    } 
} 

很好地爲我工作。

+0

正是我用過的:-) – noob 2013-12-07 23:37:12

+0

謝謝!只是想要我今天早上需要的! – 2015-08-07 10:51:58