【问题标题】:Invalid imageTag error from ImageStore.getBase64ForTag来自 ImageStore.getBase64ForTag 的无效 imageTag 错误
【发布时间】:2017-01-31 21:55:35
【问题描述】:

我正在尝试从 facebook 个人资料图片中获取 base64 图像。

getImageFromFacebook() {
 const imageURL = this.props.userInfo.picture;
  Image.getSize(imageURL, (width, height) => {
   var imageSize = {width, height};
   ImageEditor.cropImage(imageURL, imageSize, (imageURI) => {
    console.log(imageURI);
    ImageStore.getBase64ForTag(imageURI, (base64Data) => {
      this.setState({pictureBase64: base64Data});
      ImageStore.removeImageForTag(imageURI);
    }, (reason) => console.log(reason) )
   }, (reason) => console.log(reason) )
  }, (reason) => console.log(reason))
}

我正在按照https://github.com/facebook/react-native/issues/1158 中描述的步骤进行操作:

  1. 使用 Image.getSize(uri) 获取图像尺寸。

  2. 使用 ImageEditor.cropImage(uri,cropData) 将图像的副本存储在 ImageStore 中(如果您传递了在步骤 1 中获得的宽度和高度),那么虽然cropImage 实际上不会裁剪图像它可能仍然会复制它。

  3. 使用 ImageStore.getBase64ForTag(uri) 获取新图像的 base64 数据(传递您从 cropImage 函数获得的 uri,而不是原始的)。

  4. 完成删除副本后,不要忘记调用 ImageStore.removeImageForTag(uri)。

虽然 ImageEditor.cropImage 返回一个有效的 URI (rct-image-store://0),但 ImageStore.getBase64ForTag 失败的原因是:

code: "ERCTERRORDOMAIN0",
domain: "RCTErrorDomain",
message: "Invalid imageTag: rct-image-store://0"

我做错了什么?

【问题讨论】:

    标签: react-native


    【解决方案1】:

    发现错误! imageSize 应该这样设置:

      var imageSize = {
        size: {
          width,
          height
        },
        offset: {
          x: 0,
          y: 0,
        },
      };
    

    【讨论】:

      猜你喜欢
      • 2011-07-21
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-15
      • 1970-01-01
      相关资源
      最近更新 更多