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')
}
}
但是这里有一个缺点,您需要创建自己的弹出窗口来通过相机或图库选择图像。除此之外,这个组件实际上是由它组成的。您可以在提到的链接中找到整个文档
推荐阅读
- r - 通过查找另一个数据框在 R 中创建一个新列
- ruby - Ruby:评估顺序取决于空格和看似多余的括号,为什么?
- reactjs - react-intl 包中 defineMessages 的打字稿
- android - 我如何为大用户群的 android 应用程序登录服务器?
- android - 通知父小部件在异步子小部件中加载数据时发生错误
- c# - 如何解决 BlazorServer 默认项目解决方案中的命名空间错误(VisualStudio 代码)
- c - 我不知道为什么在 pthread 子例程中更改变量访问/存储类型会大幅提高性能
- hadoop - 我试图运行纱线,但遇到了这个问题。纱线已安装但甚至无法访问该版本
- node.js - 我想在没有socket-io-client包的情况下使用带有flutter的socket.io v4
- json - 如何在反应中使用来自 api (json) 的数据