【问题标题】:React-native-camera don't want to save imagesReact-native-camera 不想保存图像
【发布时间】:2018-04-06 13:45:04
【问题描述】:

我在我的 react-native 应用程序中使用 react-native-camera 并且一切正常,但是当我拍照时,图片保存在我不想要的设备上,图像应该被发送到 api但没有保存在我的设备上,有谁知道我怎样才能让它不保存在设备上?

render() {
return(
  <View style={styles.container}>
    <Camera
      style={styles.camera}
      ref={ref => {this.camera = ref;}}
      type={Camera.constants.Type.back}
      flashMode={Camera.constants.FlashMode.on}
      orientation={Camera.constants.Orientation.landscapeLeft}>
      <TouchableOpacity onPress={this.takePicture.bind(this)} style={{zIndex: 100}}>
        <View style={styles.cameraButton}></View>
      </TouchableOpacity>
    </Camera>
  </View>
  );
}

takePicture()
{
  this.camera.capture()
  .then((data) => this.sendData(data))
  .catch(err => console.error(err));
}

【问题讨论】:

    标签: react-native react-native-camera


    【解决方案1】:

    正确答案是编辑#2!

    您可以在我们的 repo 中打开一个问题:https://github.com/react-native-community/react-native-camera

    图片保存在应用的缓存目录中。

    当 promise 被解析时,该对象包含一个 uri,即图像的路径。或者您可以传递选项 base64: true,以从 takePictureAsync 承诺接收图像的 base64 表示。

    使用 base64 字符串,您可以将其发送到您的服务器。这就是我们在应用中所做的。

    编辑:如果您真的不希望它保存在应用程序的缓存目录中,我们可以在 takePictureAsync 方法中创建一个选项来执行此操作。随时在我们的 repo 中作为功能请求打开有关此问题的问题。

    编辑#2:正确答案: 您使用的是 RCTCamera,它默认将图像保存在设备上。

    使用道具 captureTarget,传递值 Camera.constants.CaptureTarget.temp。 所以:

    <Camera
    ...
    captureTarget={Camera.constants.CaptureTarget.temp}
    ...
    </Camera>
    

    【讨论】:

    • 您好,谢谢您的回答,打开一个问题似乎是个好主意,但是我这周确实需要解决这个问题,目前有没有办法不保存它?您提到的 base64 会做到这一点吗?我该怎么做?
    【解决方案2】:

    你可以使用这个 API,我用它,而且很容易发送图片。

    https://github.com/react-community/react-native-image-picker

    您避免了创建相机视图的工作,当您选择照片(或拍摄照片)时,您会获得它的数据以发送到您想要的地方!

    【讨论】:

    • 我的问题不是我不能使用照片,我已经在这样做并将它发送到一个 api,所有这些都完成了,我的问题是我不想要照片要保存到我的设备上,你知道我该怎么做吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    • 2019-05-20
    相关资源
    最近更新 更多