简体   繁体   English

与Expo配合使用的React Native图像裁剪工具

[英]React Native image cropping tool that works with Expo

Is anyone aware of an image cropping tool for React Native that works within the Expo setup. 是否有人知道可以在Expo设置中使用的React Native图像裁剪工具。 The very popular react-native-image-crop-picker doesn't. 非常流行的react-native-image-crop-picker却没有。 Is there any alternatives? 还有其他选择吗? I can't seem to find any. 我似乎找不到任何东西。

You may use aspect 4:3, 16:9, 1:1 and so on 您可以使用方面4:3、16:9、1:1等

import { ImagePicker } from 'expo';

are you getting photo from gallery? 你是从画廊拿照片吗?

const photo = await ImagePicker.launchImageLibraryAsync({
   allowsEditing: true,
   aspect: [4, 3],
});

You can download the image with Expo#FileSystem and then crop the cached image with Expo#ImageManipulator Here is a sample 您可以使用Expo#FileSystem下载图像,然后使用Expo#ImageManipulator裁剪缓存的图像。这是一个示例

/*
 * @param link {string} URI of the image on the server
 * @param name {string} Name of the image with extension
 */
_downloadAndCrop = (link, name, cropSize = { width: 200, height: 200 }) => {
    FileSystem.downloadAsync(
       link,
       name
   )
   .then(({ uri }) => {
       console.log('Finished downloading to ', uri);
       //Your new cropped image
       const cropImage = ImageManipulator.manipulate(uri, [
                             crop: { 
                                 originX: 0, 
                                 originY: 0, 
                                 width: cropSize.width, 
                                 height: cropSize.height 
                             }
                         }], {});
   })
   .catch(error => {
       console.error(error);
   });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM