1

我正在尝试旋转 CameraPreviewImageSource 以使其(仅)以纵向模式显示:

    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> 

有任何想法吗?

4

2 回答 2

2

试试这个开关,宽度和高度,并添加一个旋转设置为 90 的 RotationFilter。还将设备方向设置为纵向。如果您想在应用程序的其余部分支持另一个方向,只需在OnNavigatedTo / OnNavigatedFrom中设置Orientation

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);
}
于 2014-11-12T09:06:39.280 回答
0

由于您使用 Nokia Imaging SDK 来实现此目的,您是否尝试在渲染链中添加 RotateFilter 并在需要时旋转它?

您的链将是:CameraPreviewSource -> FilterEffect [rotateFilter] -> WriteableBitmapRenderer。

于 2014-11-10T07:34:57.920 回答