Starting from Android 13, Android supports setting Mirror for each Camera Output Stream. This article introduces the specific usage method.
OutputConfiguration Added APIs for Mirror
Android 13 added the following constants to the OutputConfiguration class to represent different Mirror directions:
Constants | Value | Description |
---|---|---|
MIRROR_MODE_AUTO | 0 | Automatic mirroring based on camera facing. This is the default mirroring mode for the camera device.With this mode: The camera output is mirrored horizontally for front-facing cameras. There is no mirroring for rear-facing and external cameras. |
MIRROR_MODE_H | 2 | Camera output is mirrored horizontally. the same behavior as in AUTO mode for front facing camera. |
MIRROR_MODE_NONE | 1 | No mirror transform is applied. No mirroring is applied to the camera output regardless of the camera facing. |
MIRROR_MODE_V | 3 | Camera output is mirrored vertically. |
Android 13 added two APIs to the OutputConfiguration class to set and get the Mirror value of the current OutputConfiguration.
setMirrorMode
Syntax:
public void setMirrorMode(int mirrorMode)
Description:
- If this function is not called, the mirroring mode for this output is
MIRROR_MODE_AUTO
, with which the camera API will mirror the output images horizontally for front facing camera. - For efficiency, the mirror effect is applied as a transform flag, so it is only effective in some outputs. It works automatically for SurfaceView and TextureView outputs.
- For manual use of SurfaceTexture, it is reflected in the value of
SurfaceTexture.getTransformMatrix(float[])
. - For other end points, such as ImageReader, MediaRecorder, or MediaCodec, the mirror mode has no effect. If mirroring is needed for such outputs, the application needs to mirror the image buffers itself before passing them onward.
- For manual use of SurfaceTexture, it is reflected in the value of
getMirrorMode
Syntax:
public int getMirrorMode()
Description:
- Get the current mirroring mode.
- If no
setMirrorMode(int)
is called first, this function returnsMIRROR_MODE_AUTO
.
setMirrorMode Examples
MIRROR_MODE_NONE
when set mirror mode to MIRROR_MODE_NONE
, the preview shows like this:
MIRROR_MODE_H
when set mirror mode to MIRROR_MODE_H
, the preview shows like this:
MIRROR_MODE_V
when set mirror mode to MIRROR_MODE_V
, the preview shows like this:
Android13 Camera New Feature - Camera mirror support
Reviewed by admin
on
July 17, 2022
Rating:

No comments: