如何在React Native中裁剪图片

5
我正在使用 react-native-camera 拍照。拍摄的照片是16/9的比例,但我需要它们是4/3的比例。
因此,我想裁剪图像为例如1920*1440
我使用 React Native 的 ImageEditorImageEditor 的代码可以在这里找到。
我的代码如下:
this.camera.capture(target)
     .then((data) => {
           let cropData = {
               offset:{x:0,y:0},
               size:{width:1920, height:1440}
           };

           ImageEditor.cropImage(
                 data.path,
                 cropData, 
                 (uri) => {
                       this.props.captured(this.props.request, {
                             path: uri,
                             data: data.data,
                             longitude: position.coords.longitude,
                             latitude: position.coords.latitude
                             }
                       );
                       Actions.pop();
                 },
                 (error) => {});
            })
     .catch(err => {
           console.error(err)
     });

但是上述代码无法正常工作。保存的照片没有被裁剪,且其大小仍为 1440*2560
有什么建议吗?

你解决了这个问题吗? - merry-go-round
1个回答

0

captured()中,您的代码发生了什么并不完全清楚,但我认为问题在于您将原始data传递给了this.props.captured。根据文档,我的理解是:

如果裁剪过程成功,则裁剪后的图像将存储在ImageStore中,并且在success回调中返回的URI将指向存储中的图像。

因此,您应该从uri中读取裁剪后的图像,而不是重用data


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接