【问题标题】:Insert image into Realm database in Android在Android中将图像插入Realm数据库
【发布时间】:2016-07-03 10:24:10
【问题描述】:

我正在编写一个 Android 应用程序,我想将帐户的个人资料图像本地保存在 Realm 数据库中。我找不到任何关于此的文档。 我该怎么做?

【问题讨论】:

  • 您需要将其保存为byte[]

标签: android realm


【解决方案1】:

首先,convert bitmap to byte array

Bitmap bmp = intent.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

稍后,将 byte[] 保存到 Realm 中

注意:字符串和字节数组 (byte[]) 不能大于 16 MB(来自 Realm 文档)

字段类型

Realm 支持以下字段类型:boolean、byte、short、ìnt、 long、float、double、String、Date 和 byte[]。整数类型字节, short、int 和 long 都映射到同一个类型(实际上是 long) 境界之内。此外,还支持 RealmObject 和 RealmList 的子类来建模关系。

【讨论】:

    猜你喜欢
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 2022-01-16
    相关资源
    最近更新 更多