在Windows Phone的8.1之前保存图像旋转 [英] Rotate image before saving in Windows Phone 8.1

查看:174
本文介绍了在Windows Phone的8.1之前保存图像旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用应当从相机保存图像。我写了下面的代码:

My app should save an image from camera. I wrote the code below:


  1. 方法,它初始化相机。

  1. Method which initializes the camera.

Windows.Media.Capture.MediaCapture takePhotoManager;
public async void InitializeCamera()
{
    takePhotoManager = new Windows.Media.Capture.MediaCapture();

    await takePhotoManager.InitializeAsync();
    takePhotoManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
    PhotoPreview.Source = takePhotoManager;
    await takePhotoManager.StartPreviewAsync();
    // to stop it
    //await takePhotoManager.StopPreviewAsync();
}


  • 方法既节约了一张照片:

  • Method which saves a photo:

    public async void SavePhoto()
    {
        ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
    
        var file = await KnownFolders.PicturesLibrary.CreateFileAsync("Photo.jpg", CreationCollisionOption.ReplaceExisting);
    
        await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file);
    }
    


  • 预览

  • Preview

        <CaptureElement x:Name="PhotoPreview" FlowDirection="LeftToRight"
            HorizontalAlignment="Center" 
            VerticalAlignment="Center" 
            Stretch="UniformToFill">
        </CaptureElement>
    


  • 我有两个问题:
    1.预览不会填满整个空间

    I have two problems: 1. The preview does not fill the entire space


    1. 保存我得到这样的事情后。(不旋转和两侧的透明层)结果

    感谢

    推荐答案

    我觉得问题可能出在您所使用的面板。正如我无法看到的 Grid.Row 的财产您的 CaptureElement 的XAML中那么我怀疑你正在使用的的StackPanel 的 - 那就是赢得了面板'T延伸到你的屏幕,它只是堆栈的元素。

    I think the problem may be in the panel you are using. As I can't see Grid.Row property in your CaptureElement in XAML then I suspect that you are using StackPanel - it's a panel that won't stretch to your screen it just stacks elements.

    您正在尝试做的事情有可能需要的电网的,因为我检查下面的代码应该工作:

    The thing you are trying to do should be possible with Grid, as I've checked the following code should work:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    
        <StackPanel Orientation="Vertical" Grid.Row="0">
            <Button Click="InitCameraBtn_Click" Content="Initialize Camera" />
            <Button Click="StartPreviewBtn_Click" Content="Start Capture Preview" />
            <Button Click="StopPreviewBtn_Click" Content="Stop Capture Preview" />
        </StackPanel>
    
        <CaptureElement x:Name="PhotoPreview" Stretch="UniformToFill" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
    </Grid>
    

    这篇关于在Windows Phone的8.1之前保存图像旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆