pio*_*lut 6 c# rotation windows-runtime windows-phone-8.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();
}
Run Code Online (Sandbox Code Playgroud)保存照片的方法:
public async void SavePhoto()
{
ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
var file = await KnownFolders.PicturesLibrary.CreateFileAsync("Photo.jpg", CreationCollisionOption.ReplaceExisting);
await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file);
}
Run Code Online (Sandbox Code Playgroud)预习
<CaptureElement x:Name="PhotoPreview" FlowDirection="LeftToRight"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Stretch="UniformToFill">
</CaptureElement>
Run Code Online (Sandbox Code Playgroud)我有两个问题:1.预览不会填满整个空间


谢谢
我认为问题可能出在您使用的面板上。由于我在 XAML 中的CaptureElement中看不到Grid.Row属性,因此我怀疑您正在使用StackPanel - 它是一个不会拉伸到屏幕的面板,它只是堆叠元素。
您尝试做的事情应该可以通过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>
Run Code Online (Sandbox Code Playgroud)