世博相机保持正面照片镜像?

expo-camera keep front facing photo mirrored?

我正在使用 expo-camera 库拍摄自拍图像。预览是镜像的,但保存的图像恢复到正常方向。如何防止这种效果发生(我希望图像保持镜像),或者如果不能,我如何水平翻转图像?

以下是我目前拍摄的照片:

const takePic = async () => {
  if (cameraRef) {
    const photo = await cameraRef.current.takePictureAsync();
    setFrontProfile(photo.uri);
  }
};

使用ImageManipulator翻转它。

我知道@Kartikey 已经回答了这个问题,但我想直接回答作者的问题。

@Kartikey 给出的 link 中的示例将旋转设置为 90 而不是 180。我的回答在应用操作之前检查照片是否来自前置摄像头,并且非常适合给定的代码干净。

import { manipulateAsync, FlipType, SaveFormat } from 'expo-image-manipulator';

...

const takePic = async () => {
    if (!cameraRef) return;
    
    let photo = await cameraRef.takePictureAsync();

    if (cameraType === Camera.Constants.Type.front) {
        photo = await manipulateAsync(
            photo.localUri || photo.uri,
            [
                { rotate: 180 },
                { flip: FlipType.Vertical },
            ],
            { compress: 1, format: SaveFormat.PNG }
        );
    }

    setFrontProfile(photo.uri);
};