c# - 在 Windows Phone 8.1 中保存前旋转图像

标签 c# rotation windows-runtime windows-phone-8.1

我的应用程序应该保存来自相机的图像。我写了下面的代码:

  1. 初始化相机的方法。

    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();
    }
    
  2. 保存照片的方法:

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

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

我有两个问题: 1.预览没有填满整个空间 enter image description here

  1. 保存后我得到这样的东西:(没有旋转,两边都有透明层)。
    enter image description here

谢谢

最佳答案

我认为问题可能出在您使用的面板上。由于我在 XAML 中的 CaptureElement 中看不到 Grid.Row 属性,因此我怀疑您正在使用 StackPanel - 这是一个成功的面板'拉伸(stretch)到您的屏幕,它只是堆叠元素。

您尝试做的事情应该可以通过 Grid 实现,因为我已经检查过以下代码应该可以工作:

<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>

关于c# - 在 Windows Phone 8.1 中保存前旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26360023/

相关文章:

c# - 正则表达式在文件夹中查找文件

c# - 反序列化.json 到位图图像c#

c# - WPF:解析几何忽略语言

uiview - 基于UITouch旋转UIView

iphone - CATransform3DMakeRotation 的奇怪视角

ios - 在倒置肖像模式下关闭 VC 后,主 VC 显示为正常肖像

c# - 使用 C# 在 WinRT 应用程序中获取当前时间格式。

xaml - 当指针/鼠标结束时如何更改 gridview 项目边框

windows-8 - FluidMoveBehavior 可用吗?

c# - 获取通用枚举的基础值