Image Editor Native module for React Native.
yarn add @react-native-community/image-editor
or
npm install @react-native-community/image-editor --save
react-native link @react-native-community/image-editor
Start by importing the library:
import ImageEditor from "@react-native-community/image-editor";
Crop the image specified by the URI param. If URI points to a remote image, it will be downloaded automatically. If the image cannot be loaded/downloaded, the promise will be rejected.
If the cropping process is successful, the resultant cropped image will be stored in the cache path, and the URI returned in the promise will point to the image in the cache path. Remember to delete the cropped image from the cache path when you are done with it.
ImageEditor.cropImage(uri, cropData).then(url => {
console.log("Cropped image uri", url);
})
Property | Required | Description |
---|---|---|
offset |
Yes | The top-left corner of the cropped image, specified in the original image's coordinate space |
size |
Yes | Size (dimensions) of the cropped image |
displaySize |
No | Size to which you want to scale the cropped image |
resizeMode |
No | Resizing mode to use when scaling the image (iOS only, android resize mode is always 'cover') Default value: 'contain' |
cropData = {
offset: {x: number, y: number},
size: {width: number, height: number},
displaySize: {width: number, height: number},
resizeMode: 'contain' | 'cover' | 'stretch',
};
For more advanced usage check our example app.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。