【发布时间】: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 中描述的步骤进行操作:
使用 Image.getSize(uri) 获取图像尺寸。
使用 ImageEditor.cropImage(uri,cropData) 将图像的副本存储在 ImageStore 中(如果您传递了在步骤 1 中获得的宽度和高度),那么虽然cropImage 实际上不会裁剪图像它可能仍然会复制它。
使用 ImageStore.getBase64ForTag(uri) 获取新图像的 base64 数据(传递您从 cropImage 函数获得的 uri,而不是原始的)。
完成删除副本后,不要忘记调用 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