我"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 …Run Code Online (Sandbox Code Playgroud) react-native expo react-native-vision-camera react-native-orientation-locker