Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42670

Proper way to perform camera preview mirroring mode

Currently, when tested using Media capture using capture device sample, I realize the camera is not something I want. I wish it to be in mirroring mode. Currently, it is not.

  1. For a camera preview to be in mirroring mode, may I know is it hardware dependent or hardware independent. Possible that if I run the same code with different hardware, the camera preview will be in mirroring mode? If it is hardware dependent, how can I check whether my camera preview is in mirroring/non-mirroring mode?

  2. To make it in mirroring mode, I try to follow this thread. I try MediaCapture.SetPreviewMirroring(true). No effect as all. The camera preview is still in non-mirroring mode.

  3. I try captureElement.RenderTransform = new ScaleTransform() { ScaleX = -1 };. The whole camera preview become plain grey color.

  4. The last approach I would like to try, is try to perform flipping in C++ code through MediaCapture.AddEffectAsync(). However, that need to go back to my first question. Can I just simply perform flipping, or do I first need to check whether the incoming buffer is in mirroring/non-mirroring mode? If yes, how do I check?

Upvotes: 3

Views: 769

Answers (2)

Tam Bui
Tam Bui

Reputation: 3048

For those looking for a more updated answer since this question was asked, the proper way on UWP and WinUI is to set the FlowDirection="RightToLeft" on the CaptureElement.

<CaptureElement x:Name="previewElement" FlowDirection="RightToLeft"/>

Upvotes: 2

Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42670

Use

    <CaptureElement x:Name="previewElement" Margin="0" Stretch="UniformToFill" RenderTransformOrigin="0.5,0.5">
        <CaptureElement.RenderTransform>
            <CompositeTransform ScaleX="-1"/>
        </CaptureElement.RenderTransform>
    </CaptureElement>

The key lied on RenderTransformOrigin="0.5,0.5". We need to flip from center of preview.

Upvotes: 0

Related Questions