我将以react-native方式旋转图像,我想获得旋转图像的base64。我用了几个库
react-native-image-rotate
:在Android上运行良好,但在iOS上我将rct-image-store://1
作为网址,因此我尝试使用rn-fetch-blob
获取base64,但会引发无法识别该网址的错误。
react-native-image-resizer
:我使用了此功能,但在iOS中响应不佳。如果我设置-90然后旋转-180,如果我设置-180然后旋转为-270。
请帮助我解决这个问题,如何在iOS中旋转图像。
我需要将图像旋转为-90,-180,-270,-360(原始)。
这是到目前为止我的工作良好的代码
rotateImage = (angle) => {
const { currentImage } = this.state; // origin Image, you can pass it from params,... as you wish
ImageRotate.rotateImage( // using 'react-native-image-rotate'
currentImage.uri,
angle,
(rotatedUri) => {
if (Platform.OS === 'ios') {
ImageStore.getBase64ForTag( // import from react-native
rotatedUri,
(base64Image) => {
const imagePath = `${RNFS.DocumentDirectoryPath}/${new Date().getTime()}.jpg`;
RNFS.writeFile(imagePath, `${base64Image}`, 'base64') // using 'react-native-fs'
.then(() => {
// now your file path is imagePath (which is a real path)
if (success) {
this.updateCurrentImage(imagePath, currentImage.height, currentImage.width);
ImageStore.removeImageForTag(rotatedUri);
}
})
.catch(() => {});
},
() => {},
);
} else {
this.updateCurrentImage(rotatedUri, currentImage.height, currentImage.width);
}
},
(error) => {
console.error(error);
},
);
};
我认为您已完成rotatedUri
。
ImageStore
中通过react-native
获得base64。 react-native-fs
将其写入本地图像>之后,您拥有imagePath
是本地图像。