裁剪图像的本机图像很小

时间:2019-12-11 19:28:42

标签: android ios image react-native image-processing

我想裁剪图像,所以我使用了@react-native-community/image-editor 我想从base64图像中裁剪图像,所以我也使用了RNFetchBlob。这是我的代码。

const file_path =
      RNFetchBlob.fs.dirs.DocumentDir + '/' + new Date().getTime() + '.jpg';
RNFetchBlob.fs
      .writeFile(file_path, this.state.image, 'base64')
      .then(res => {
        console.log(res);
        ImageEditor.cropImage(
          'file:///' + file_path,
          {
            offset: {x: topX, y: topY},
            size: {width: bottomX - topX, height: bottomY - topY},
            displaySize: {width: bottomX - topX, height: bottomY - topY},
          },
          'PNG',
        ).then(url => {
          console.log(url);
          this.setState({visible: true, cropedImage: url});
        });
      });

它可以在Android上运行,但是在iOS中它很小,只有20 * 20像素,即使我将尺寸设置为超过1000像素也是如此。 我应该将裁剪后的图像上传到服务器,因此需要裁剪后的图像文件。 谢谢您的回答。

1 个答案:

答案 0 :(得分:0)

问题是我设置了resizeMode ='center',我将其更改为'contain',它解决了我的问题。