Rotating VideoCaptureElement

May 6, 2016 at 8:48 AM
I use WPFMediakit to show web cam livestream on a tablet. When the tablet is rotated I have problems with displaying the preview correctly (keeping aspect ratio). Depending on ScreenInformation.ScreenConfig I apply a rotate transformationen and a scale transformation. The aspect ratio of 1280 x 720 should be preserved. This is what I tried:
    <StackPanel Background="Red">
        <controls:VideoCaptureElement
                FPS="30"
                x:Name="VideoElement"
                HorizontalAlignment="Center"
                LoadedBehavior="Manual"
                VerticalAlignment="Center"
                Height="720"
                Width="1280"
            DesiredPixelHeight="720"
            DesiredPixelWidth="1280"
                UnloadedBehavior="Close" >
            <controls:VideoCaptureElement.LayoutTransform>
                <TransformGroup>
                    <ScaleTransform CenterX="0" CenterY="0" ScaleX="{Binding ElementName=This, Path=PreviewScaleX}" ScaleY="{Binding ElementName=This, Path=PreviewScaleY}"/>
                    <RotateTransform Angle="{Binding ElementName=This, Path=RotationAngle}"/>
                </TransformGroup>
            </controls:VideoCaptureElement.LayoutTransform>
        </controls:VideoCaptureElement>
    </StackPanel>
In the DisplaySettingsChanged Callback, I set the respective Properties in code-behind:
    void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e) {
        if (SystemInformation.ScreenOrientation == ScreenOrientation.Angle0) {
            RotationAngle = 0;
            PreviewScaleX = 1;
            PreviewScaleY = 1;
        }
        if (SystemInformation.ScreenOrientation == ScreenOrientation.Angle90) {
            RotationAngle = 90;
            PreviewScaleX = 0.5;
            PreviewScaleY = 0.5;

        }
        if (SystemInformation.ScreenOrientation == ScreenOrientation.Angle180) {
            RotationAngle = 180;
            PreviewScaleX = 1;
            PreviewScaleY = 1;

        }
        if (SystemInformation.ScreenOrientation == ScreenOrientation.Angle270) {
            PreviewScaleX = 0.2;
            PreviewScaleY = 0.2;
            RotationAngle = 270;
        }
    }
Does anyone have any advice on how rotation really works?

Greets, Trinity