gpt4 book ai didi

android - 如何在 Room 数据库中存储来自 url 的图像 (Java)

转载 作者:行者123 更新时间:2023-11-30 04:54:22 25 4
gpt4 key购买 nike

我正在将整个 API 响应发送到 Room 数据库以供离线访问。我已经设法存储了所有字符串值,但我也想将图像(获取图像 url 作为响应)存储到数据库中。由于我没有使用 Room 数据库的经验,我对如何将图像存储在 Room db 列中感到困惑以下是 API 响应

{
"beast": [{
"id": "1",
"name": "The Griffin of Edward III",
"description": "The English Beast has always been a lion",
"image": "www.google.com/uploads/beast-images/2.png"
},
{
"id": "2",
"name": "The Lion of England",
"description": "The English Beast has always been a lion",
"image": "www.google.com/uploads/beast-images/2.png"
}]
}

最佳答案

您应该使用 BLOB 数据类型来存储图像。只需使用 @ColumnInfo(typeAffinity = ColumnInfo.BLOB) 注释 Room 模型类中的图像字段。看这个answer获取更多信息。

关于android - 如何在 Room 数据库中存储来自 url 的图像 (Java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59488268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com