本文原创首发于公众号:ReactNative开发圈,转载需注明出处。react
React Native图片选择裁剪组件:react-native-image-crop-picker,支持安卓和IOS双平台,支持从相册、相机选择图片和视频,能够单选和多选,能够压缩和裁剪。
npm i react-native-image-crop-picker --save react-native link react-native-image-crop-picker
若是须要操做视频,须要安装git
npm i react-native-video --save react-native link react-native-video
由于须要操做相册和相机,IOS须要增长隐私访问说明,修改info.plist文件增长如下项:github
<key>NSPhotoLibraryUsageDescription</key> <string>此 App 须要您的赞成才能读取相册</string> <key>NSCameraUsageDescription</key> <string>此 App 须要您的赞成才能使用相机</string>
ImagePicker.openPicker({ width: 300, height: 400, cropping: true }).then(image => { console.log(image); });
ImagePicker.openPicker({ multiple: true }).then(images => { console.log(images); });
ImagePicker.openPicker({ mediaType: "video", }).then((video) => { console.log(video); });
ImagePicker.openCamera({ width: 300, height: 400, cropping: true }).then(image => { console.log(image); });
ImagePicker.openCropper({ path: 'my-file-path.jpg', width: 300, height: 400 }).then(image => { console.log(image); });
完整代码:GitHub - forrest23/ReactNativeComponents: React Native组件大全,介绍React Native经常使用组件的使用方法和使用示例
本次示例代码在 Component08文件夹中。请不要吝啬大家的Star!npm
微信不让跳转外链,能够点击查看原文来查看外链GitHub内容。微信
举手之劳关注个人微信公众号:ReactNative开发圈ide