I'm trying to rotate a CameraPreviewImageSource to make it appear (only) in portrait mode:
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;
}
I also tried in the XAML file, but most of the time the result is weird (like 90% of the picture is hidden):
<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>
Any ideas?