我的应用程序应该保存来自相机的图像。我写了下面的代码:
初始化相机的方法。
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(); }
保存照片的方法:
public async void SavePhoto() { ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg(); var file = await KnownFolders.PicturesLibrary.CreateFileAsync("Photo.jpg", CreationCollisionOption.ReplaceExisting); await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file); }
预览
<CaptureElement x:Name="PhotoPreview" FlowDirection="LeftToRight" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="UniformToFill"> </CaptureElement>
我有两个问题: 1.预览没有填满整个空间
- 保存后我得到这样的东西:(没有旋转,两边都有透明层)。
谢谢
最佳答案
我认为问题可能出在您使用的面板上。由于我在 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/