C# 让相机在纵向模式下正常工作

C# 让相机在纵向模式下正常工作,c#,windows-phone-7,xaml,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" >

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

下面是我在.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>    
SupportedOrientations=“肖像”Orientation=“肖像”
mc:Ignorable=“d”d:DesignHeight=“800”d:DesignWidth=“480”
这是我在.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);
    }
受保护的覆盖无效OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if(支持PhotoCamera.IsCameraType(CameraType.FrontFacing))
{
cam=新的Microsoft.Devices.PhotoCamera(CameraType.FrontFacing);
}
其他的
{
cam=新的Microsoft.Devices.PhotoCamera(CameraType.Primary);
}
cam.Initialized+=新的事件处理程序(cam_Initialized);
cam.CaptureCompleted+=新事件处理程序(cam_CaptureCompleted);
cam.CaptureImageAvailable+=新的事件处理程序(cam\u CaptureImageAvailable);
cam.capturatumbnailavailable+=新事件处理程序(cam\u capturatumbnailavailable);
viewfinderBrush.SetSource(cam);
}
问题是我拿着手机,把手机对准一个人。屏幕在屏幕右侧显示人的头部,在屏幕左侧显示人的脚。 当他们站在我面前时,头应该在屏幕的顶部,脚应该在底部,因为这些人不是超人

因此,在出现在屏幕上之前,摄像机的图像似乎已经旋转了-90度

有人能解释出哪里出了问题,我需要实现什么样的示例代码来解决这个问题吗

谢谢,
-代码

您需要实现VideoBrush.RelativeTransform,如下文所述:-

还包括以下内容:-


只需将这一行添加到相机页面的C代码中即可。它将在纵向模式下正确变换和处理相机视频流

viewfinderTransform.Rotation = 90;