查看以横向拍摄的照片,以“纵向”方向查看,并保存以使其不旋转

Phi*_*cks 6 react-native expo react-native-vision-camera react-native-orientation-locker

我"react-native-vision-camera": "^2.15.4",在我的 Expo 项目中使用(SDK 46,RN,0.69.9)。该expo-camera模块不支持不同的镜头,因此需要切换。

当我以纵向或横向方向拍照时,照片显示为photo.metadata.Orientation: 6

这让我很惊讶。

在此输入图像描述 在此输入图像描述

我希望在拍摄照片后旋转图像的预览,使其水平且更易于查看。它也垂直保存,因此在网络上,它的旋转也错误。

<Camera
  // Do not add enableZoomGesture since using the Animated lib
  // enableZoomGesture
  ref={cameraRef}
  photo
  device={device}
  isActive={isActive}
  format={formats?.[0]}
  animatedProps={animatedProps}
  orientation={'portrait'}
/>
Run Code Online (Sandbox Code Playgroud)

显然,相机组件中的orientation道具也没有按预期运行。

为什么元数据上的方向相同?如何让照片在拍摄后正确旋转,以便保存为以水平“纵向”方向查看?


编辑此后我尝试过react-native-orientation-locker. 虽然它不会锁定正在捕获的图像,但我至少可以在捕获事件之后自定义图像:

const capturePhoto = async () => {
    if (cameraRef?.current && !snapping) {
      setSnapping(true);
      const photo = await cameraRef.current.takePhoto({
        flash: flashMode,
      });

      let rotation = 0;

      if (orientation === OrientationType['LANDSCAPE-LEFT']) {
        rotation = -90;
      } else if (orientation === OrientationType['LANDSCAPE-RIGHT']) {
        rotation = 90;
      } else if (orientation === OrientationType['PORTRAIT-UPSIDEDOWN']) {
        rotation = 180;
      }

     // now use `expo-image-manipulator`
      const photoWithOrientation = await manipulateImage({
        imageUri: photo.path,
        actions: [{ rotate: rotation }],
        saveOptions: {
          compress: 1,
        },
      });

      handleSaveAsset([
        {
          path: photoWithOrientation.uri,
          width: photoWithOrientation.width,
          height: photoWithOrientation.height,
          isRawPhoto: false,
        },
      ]);
    }
  };
Run Code Online (Sandbox Code Playgroud)

有没有办法消除这种逻辑,使图像在审查时始终“垂直”,或者这是正确的方法吗?

小智 -1

         <Camera
          ref={camera}
          style={[StyleSheet.absoluteFillObject]}
          device={device}
          isActive={true}
          zoom={0}
          photo
          orientation={'portrait'}
        />
Run Code Online (Sandbox Code Playgroud)