在android中将图像插入realm数据库

我正在编写 Android应用程序,我想在Realm数据库中本地保存配置文件的图像.我找不到任何关于这方面的文件.
我怎样才能做到这一点 ???

解决方法

首先,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 supports the following field types: boolean,byte,short,ìnt,long,float,double,String,Date and byte[]. The integer types byte,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.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...