简体   繁体   中英

How to add images to Realm Database in Android?

I am trying to implement a login (no register) service in my application using Realm as database . It is the first time I am trying to use this so I am really new to Realm. I have read Realm documentation but I wasn't able to figure out how can I add Image to Realm and use it in my app.

The scenario is like this: I have predefined username and password set and when user logins with that username and password, I want to update the Account Header Image in Navigation Drawer to that username and password . Also, user can update the Account Header Image too.

I hope you guys were able to understand my scenario. Please help me with this.

Any help is greatly appreciated. Thanks. :)

Anmol

Realm documentations say the following limitation:

Strings and byte arrays (byte[]) cannot be larger than 16 MB.

The recommended way is to save the path to a file instead of the actual image.

One of the ways to do so is to convert image into base64 string and store it as a string in realm database.

While retrieving, decode that base 64 string to image and use it.

Here is a link of how to convert image to base64

Another not so reliable solution is download the image into some file and store the file path in realm

如果blob数据类型在领域中可用,则可以将图像字节数组存储在blob中

如果您有较大的位图(图像),最好将图像存储在磁盘上,并将路径存储在Realm中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM