2

捕获图像时,它会保存两张图像,一张是原始图像,另一张是压缩图像,并给出压缩图像的路径image.path。如何禁用在图库中保存任何图像,我只需要使用 base64 即可?

ImagePicker.openCamera({
  cropping: true,
  width: 300*3,
  height: 400*3,
  includeBase64: true,
  mediaType:'photo',
}).then(image => {
  console.log('received image');
  console.log(image)
})

输出如下:

cropRect: {height: 4128, width: 3096, y: 0, x: 0}
data: "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQ"
height: 900
mime: "image/jpeg"
modificationDate: "1581938243000"
path: "file:///storage/emulated/0/Pictures/398da0f6-73ee-47ce-bfdd-8b0fa68312a5.jpg"
size: 353210
width: 675
4

1 回答 1

0

一种解决方法是删除保存的图像。您可以通过执行使用 fs 包

var RNFS = require('react-native-fs');
RNFS.exists(image.path)
.then(path => RNFS.unlink(path)) 

另外,它还保存在 tmp 目录中,所以也使用它

ImagePicker.clean().then(..)
于 2020-07-13T21:26:12.870 回答