10

I'm writing an Android application and I would like to save the profile image of an account locally in a Realm database. I can't find any documentation about that. How can I do that?

1
  • 1
    You need to save it as a byte[]. Commented Mar 17, 2016 at 8:06

1 Answer 1

32

First, 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();

Later, save byte[] into Realm

Notice: Strings and byte arrays (byte[]) cannot be larger than 16 MB (from Realm Documentation)

Field types

Realm supports the following field types: boolean, byte, short, ìnt, long, float, double, String, Date and byte[]. The integer types byte, short, int, and long are all mapped to the same type (long actually) within Realm. Moreover, subclasses of RealmObject and RealmList are supported to model relationships.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.