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

Ken*_*Ken 3 javascript reactjs react-native expo expo-camera

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

到目前为止,我所拍摄的照片如下:

const takePic = async () => {
  if (cameraRef) {
    const photo = await cameraRef.current.takePictureAsync();
    setFrontProfile(photo.uri);
  }
};
Run Code Online (Sandbox Code Playgroud)

小智 7

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

@Kartikey 给出的链接中的示例将旋转设置为 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);
};
Run Code Online (Sandbox Code Playgroud)


Kar*_*key 5

使用ImageManipulator来翻转它。