【问题标题】:ViewFinder Orientation With Windows Phone 7 Mango PhotoCamera带有 Windows Phone 7 芒果照片相机的取景器方向
【发布时间】:2011-07-29 07:28:36
【问题描述】:

我正在使用带有 Windows Phone 7 Mango Beta 2 开发工具的 PhotoCamera 控件。

相机控件的“取景器”是一个用 VideoBrush 填充的矩形对象,如下例所示:

http://msdn.microsoft.com/en-us/library/hh202956%28v=VS.92%29.aspx

我的问题是,当我在手机上运行应用程序时,取景器图像总是逆时针旋转 90 度。无论手机如何定位都是如此。

有人知道如何正确定位取景器吗?

【问题讨论】:

  • 你设置了 SuppoertedOrientations="PortraitOrLandscape" 吗?
  • 这是否意味着将其设置为 PortraitOrLandscape 不会有任何影响?

标签: camera windows-phone-7


【解决方案1】:

是的,方向是您需要通过相对变换来管理的:

<!--Camera viewfinder >-->
<Rectangle Grid.Row="1"
            x:Name="preview">
  <Rectangle.Fill>
    <VideoBrush x:Name="previewBrush">
      <VideoBrush.RelativeTransform>
        <CompositeTransform x:Name="previewTransform"
                            CenterX=".5"
                            CenterY=".5" />
      </VideoBrush.RelativeTransform>
    </VideoBrush>
  </Rectangle.Fill>
</Rectangle>

然后您可以使用 PhotoCamera 类来确定要如何旋转它:

double cameraRotation = theCamera.Orientation;

// Use the orientation to determine how to transform 
// the camera preview
previewTransform.Rotation = theCamera.Orientation + 90.0; // Landscape? 

HTH

【讨论】:

  • 但它会采用 4:3 的图像并将其压缩以适应 3:4 的帧,从而使图片失真......
【解决方案2】:

为答案添加更多说明:文档描述的一件事在这里没有提到是在 OnOrientationChanged 事件中调整了相对变换。另一个区别是 XAML 中未指定相对转换。

在文档 (How to: Create a Base Camera Application for Windows Phone) 中,矩形是用视频画笔填充的,如下所示:

<!--Camera viewfinder >-->
<Rectangle Width="640" Height="480" 
           HorizontalAlignment="Left" 
           x:Name="viewfinderContainer">

    <Rectangle.Fill>
        <VideoBrush x:Name="viewfinderBrush" />
    </Rectangle.Fill>
</Rectangle>

然后,在代码隐藏中,OnOrientationChanged 事件根据方向旋转矩形:

    // Ensure that the viewfinder is upright in LandscapeRight.
    protected override void OnOrientationChanged(OrientationChangedEventArgs e)
    {
        if (e.Orientation == PageOrientation.LandscapeRight)
        {
            viewfinderBrush.RelativeTransform =
                new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 180 };
        }
        else
        {
            viewfinderBrush.RelativeTransform =
                new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 0 };
        }

        base.OnOrientationChanged(e);
    }

本主题中的代码(对应于示例)被配置为仅使用横向,也许这就是为什么您只获取横向图像的原因(?)一开始,以下属性被添加到手机中: MainPage.xaml 中的 PhoneApplicationPage 元素:

SupportedOrientations="Landscape" Orientation="LandscapeLeft"

如果图像的方向仍然不正确,请将图像同步到您的 PC 并查看它们的方向是否正确,同时在那里(在您的 PC 上)查看它们。可能是 Beta 版的错误导致图像无法正确显示在设备上。

希望对您有所帮助。干杯

【讨论】:

    【解决方案3】:

    你不需要做那么多代码,假设你处于纵向模式,只需调用:

    viewfinderBrush.RelativeTransform 
        = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 };
    

    当然,无论取景器使用什么方向,生成的图像仍然是横向的!有人知道如何最好地解决这个问题吗?

    【讨论】:

      【解决方案4】:

      是的,我删除了 OnOrientationChanged-Eventhandler 并设置了转换。当然,在 Xaml 中,我将方向更改为纵向。

      现在,取景器显示纵向,页面也是纵向的。但是图像会作为缩略图保存到相机胶卷中,因此我可以直接在设备上看到捕获的图像仍然是横向的。

      如果有人能验证这是一个 Beta 版错误,或者我们只是在这里做了一些愚蠢的代码,那就太好了;)

      谢谢。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多