繁体   English   中英

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

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

是否有人知道可以在Expo设置中使用的React Native图像裁剪工具。 非常流行的react-native-image-crop-picker却没有。 还有其他选择吗? 我似乎找不到任何东西。

您可以使用方面4:3、16:9、1:1等

import { ImagePicker } from 'expo';

你是从画廊拿照片吗?

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

您可以使用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