让相机在人像模式下正常工作

时间:2012-04-25 14:17:59

标签: c# windows-phone-7 xaml

我将相机添加到我的应用程序中,该应用程序全部处于纵向模式,因此希望保持这种方式。

以下是我在.XAML中使用的相关代码段

SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="480"

    <Canvas x:Name="viewfinderCanvas" Width="480" Height="800" >
        <!--Camera viewfinder -->
        <Canvas.Background>
            <VideoBrush x:Name="viewfinderBrush">
            </VideoBrush>
        </Canvas.Background>
    </Canvas>    

这是我在.XAML.CS

中的设置代码
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
         if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing))
         {
            cam = new Microsoft.Devices.PhotoCamera(CameraType.FrontFacing);
         }
         else
         {
            cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
         }

         cam.Initialized += new EventHandler<Microsoft.Devices.CameraOperationCompletedEventArgs>(cam_Initialized);
         cam.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(cam_CaptureCompleted);
         cam.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(cam_CaptureImageAvailable);
         cam.CaptureThumbnailAvailable += new EventHandler<ContentReadyEventArgs>(cam_CaptureThumbnailAvailable);
         viewfinderBrush.SetSource(cam);
    }

问题是我将手机放在肖像中并将手机指向一个人。屏幕显示屏幕右侧的人员头部和屏幕左侧的人员脚部。 当他们站在我面前时,头部应位于屏幕的顶部,并且底部有脚,因为这些人不是超人。

所以看起来相机的图像在屏幕上显示之前会旋转-90。

任何人都可以解释什么是错误的以及我需要实现哪些示例代码来解决这个问题。

谢谢, -code

2 个答案:

答案 0 :(得分:3)

您需要实现VideoBrush.RelativeTransform,详见以下文章: -

http://msdn.microsoft.com/en-us/magazine/hh708750.aspx

还包括以下内容: -

ViewFinder Orientation With Windows Phone 7 Mango PhotoCamera

答案 1 :(得分:1)

只需将此行添加到相机页面的C#代码即可。它将正确地以纵向模式转换和处理相机视频流。

viewfinderTransform.Rotation = 90;