如何在React Native中裁剪图像

Bok*_*oky 5 javascript react-native

我正在使用react-native-camera拍照.拍摄的照片是16/9比例,但我需要它们在4/3.

因此我想要的是例如裁剪图像1920*1440.

我使用React Native的ImageEditor.代码ImageEditor可以在这里找到.

我的代码如下:

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)
     });
Run Code Online (Sandbox Code Playgroud)

但上面的代码不起作用.保存的照片不会被裁剪,它是1440*2560.

有什么建议?

Lau*_*t S 0

目前尚不完全清楚 中的代码会发生什么captured(),但我认为问题在于您将原始代码传递datathis.props.captured. 我对文档的理解是:

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

因此data,您应该从以下位置读取裁剪后的图像,而不是重复使用uri