如何将图像的 uri 插入到 Android 中的 sqlite 数据库中?
我正在编写一个使用相机意图拍照的应用程序。我获取了图像的 uri(保存在图库中),并且可以在 ImageView 中显示图像。我试图找出将此 uri 保存在 SQLite 数据库中的最佳方法,以便稍后检索它并将图像放入 ImageView 中。我是否使用 BLOB 来存储 uri?如果是这样,我该怎么做?或者我是否将 uri 转换为字符串并以这种方式存储?我一直在寻找答案,但我一定使用了错误的搜索词,因为我找不到一个简单问题的答案。
I am writing an app that uses the camera intent to take a picture. I get the uri of the image (which is saved in the gallery) and can display the image in the ImageView. I am trying to figure out the best way to save this uri in the SQLite database in order to retrieve it later and put the image in the ImageView. Do I use a BLOB to store the uri? If so, how would I do this? Or do I convert the uri to a String and store it that way? I've been searching for an answer and I must be using the wrong search words, because I can't find an answer to what should be a simple question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您稍后想要如何访问它。对于您正在考虑的内容,有两种选择,因为图像已经保存在您的手机上,所以无需将其保存为 blob 两次。或者,如果您要移动手机上的图像或将其删除,将其放在 blob 中会更好。
实际上,您最好将图像保存在专门为应用程序中的图像预留的目录中,然后读取该目录中的所有文件名以供访问。
It would depend on how you want to access it later. For what your're considering there are two options, since the image is already saved on you phone, there is no need to save it twice as a blob. Or if you will move the image on the phone or remove it, having it in a blob would be better.
In reality, you'd be better service saving the image in a directory set aside just for images from your app and then reading all the file names in that directory later for access.