我正在尝试旋转 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>
有任何想法吗?