假设我有一个图像,例如来自图像选择器的图像,如下所示:
{
"height": 2848,
"origURL": "assets-library://asset/asset.JPG?id=B84E8479-475C-4727-A4A4-B77AA9980897&ext=JPG",
"cancelled": false,
"width": 4288,
"fileSize": 342120,
"isVertical": false,
"uri": "file:///Users/sepp/Library/Developer/CoreSimulator/Devices/998C81E0-5CC6-4A3E-90C2-A7C43060220C/data/Containers/Data/Application/53F9F372-37DD-4CD2-B5E2-0D984A064686/Library/Caches/%2540anonymous%252Fcleanguide-c5413b44-e71a-4958-80a6-25b9c9e5d7a5/ImagePicker/A1D3644A-516E-4D7C-911C-2AC120B229BB.jpg"
}
查看 React Natives ImageStore (https://facebook.github.io/react-native/docs/imagestore.html( 的文档,人们会假设将该图像的 URI 传递给ImageStore.getBase64ForTag
应该返回该图像的 base64。
相反,它会产生一个错误无效的图像标签:file:///Users/sepp/Library...(为便于阅读而缩短(。
所以我的问题是:ImageStore.getBase64ForTag
期望什么样的 URI?
这篇关于 React Native 问题跟踪器的帖子给出了答案:
要使用 ImageStore.getBase64ForTag
,您首先必须将图像放入 ImageStore,这只能通过先使用 ImageEditor.cropImage
函数来完成。
这可能看起来很麻烦,但那是因为我们通常不鼓励将图像转换为 base64 数据。如果你能解释你想做什么,可能会有更好的方法,或者我们可能能够为它创建一个更好的API。