ImageStore.getBase64ForTag需要什么URI格式? [英] What URI format does ImageStore.getBase64ForTag expect?

查看:41
本文介绍了ImageStore.getBase64ForTag需要什么URI格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个图像,例如来自图像选择器"的图像,如下所示:

Suppose I have an Image, for example from the Image Picker, that looks like this:

{
  "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 ),我们会假设将该Image的URI传递给 ImageStore.getBase64ForTag 应该返回该Image的base64.

Looking at the docs for React Natives ImageStore (https://facebook.github.io/react-native/docs/imagestore.html), one would assume that passing the URI of that Image to ImageStore.getBase64ForTag should return the base64 for that Image.

相反,它会产生错误无效的图片标签:file:///Users/sepp/Library […] (为便于阅读,已缩短).

Instead it produces an error Invalid imageTag: file:///Users/sepp/Library[…] (shortened for readability).

所以我的问题是: ImageStore.getBase64ForTag 需要什么样的URI?

So my question is: What kind of URIs does ImageStore.getBase64ForTag expect?

推荐答案

React Native问题跟踪器上的这篇帖子具有答案:

要使用 ImageStore.getBase64ForTag ,首先必须将图像放入ImageStore,这只能通过首先使用 ImageEditor.cropImage 函数来完成.

To use ImageStore.getBase64ForTag, you first have to get your image into the ImageStore, which can only be done by using the ImageEditor.cropImage function first.

这似乎很麻烦,但这是因为我们通常不鼓励将图像转换为base64数据.如果您可以解释您要做什么,则可能有更好的方法,或者我们可以为此创建更好的API.

That may seem cumbersome, and it is, but that's because we generally don't encourage converting images to base64 data. If you can explain what you're trying to do, there might be a better approach, or we might be able to create a better API for it.

这篇关于ImageStore.getBase64ForTag需要什么URI格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆