gpt4 book ai didi

react-native - 如何在上传图像之前在图像选择器中裁剪图像

转载 作者:行者123 更新时间:2023-12-04 05:25:15 26 4
gpt4 key购买 nike

我是 React Native 的新手。我想在上传图像之前裁剪图像。我正在关注本教程 https://reactnativecode.com/upload-image-to-server-using-php-mysql/#comment-5335 .现在我在上传前无法裁剪图像。如何在编码中实现裁剪功能?谁能帮我?非常感谢。

最佳答案

您可以尝试使用 https://github.com/ivpusic/react-native-image-crop-picker它可以在 IOS 和 Android 中裁剪选定的图像。基本示例是

selectPhoto() {
if (this.state.selectedOption === 'camera') {
ImagePicker.openCamera({
cropping: true,
width: 500,
height: 500,
cropperCircleOverlay: true,
compressImageMaxWidth: 640,
compressImageMaxHeight: 480,
freeStyleCropEnabled: true,
includeBase64: true
}).then(image => {
this.setState({imageModalVisible: false})
this.storeUploadedData(item, image);
})
.catch(e => {
console.log(e), this.setState({imageModalVisible: false})
});

console.log('camera')
} else {
ImagePicker.openPicker({
cropping: true,
width: 300,
height: 400,
cropperCircleOverlay: true,
freeStyleCropEnabled: true,
avoidEmptySpaceAroundImage: true,
includeBase64: true
}).then(image => {
this.setState({imageModalVisible: false})
})
.catch(e => console.log(e));
console.log('gallery')
}
}

但是这里有一个缺点,您需要创建自己的弹出窗口以通过相机或图库选择图像。除此之外,该组件实际上是由它制成的。您可以在提到的链接中找到整个文档

关于react-native - 如何在上传图像之前在图像选择器中裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54490210/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com