Android save img to sqlite
来源:互联网 发布:java软件工程师教程 编辑:程序博客网 时间:2024/05/16 08:55
1、bitmap保存到SQLite 中 数据格式:
- db.execSQL("Create table express ( _id INTEGER PRIMARY KEY AUTOINCREMENT,express_no varchar(100),express_name TEXT,express_img BLOB );");
2、bitmap 变为 Blob
- ContentValues values = new ContentValues();
- final ByteArrayOutputStream os = new ByteArrayOutputStream();
- bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
- values.put("express_img", os.toByteArray());
- values.put("express_name","zf");
- values.put("express_no","zf");
- getContentResolver().insert("express", values);
3、从SQLite中读取Bitmap
- byte[] in=cur.getBlob(cur.getColumnIndex("express_img"));
- bmpout=BitmapFactory.decodeByteArray(in,0,in.length);
显示在ImageView上
- ImageView imageView = (ImageView) view.findViewById(R.id.img);
- ByteArrayInputStream stream = new ByteArrayInputStream(cur.getBlob(cur.getColumnIndex("express_img")));
- imageView.setImageDrawable(Drawable.createFromStream(stream, "img"));
总结:
inputStream: 作为数据缓存,数据写如何供别的对象读取,其方法为read();
outputStream:作为数据缓存,将来向别的对象写内容!其方法write();
- byte[] in=cur.getBlob(cur.getColumnIndex(MyUser.User.BITMAP_VALUES));
//这样也可以对数据进行初始化,byte是基本类型,不需要之前进行长度定义。
0 0
- Android save img to sqlite
- QT14 how to save data in sqlite database with pushbutton
- android download file and save to sdCard
- IOS工程师面试被问到的问题SQLite store takes a "long time" to save怎么解决?
- To Save Or Not To Save?
- Learn To Save and Load External Images in Google Android
- android studio 报错Failed to save settings解决方法记录
- SimpleCV中img.show()和img.save(display)的不同
- sleeping-to-save-cpu
- Save Image to UserDefaults
- xtraReport save to DB
- QPixmap save to png
- Save YUV to Disk
- save Objects to Files
- How to:Save Layout
- Android 修改init.rc (related to ramdisk.img)
- Android ramdisk.img system.img userdata.img
- Android ramdisk.img system.img userdata.img
- Unity
- c++ extern "C"
- Length of Last Word
- C#钩子应用实例
- 几类ARM中断的区别
- Android save img to sqlite
- 不用打开视频、音频文件就能获取视频、音频的时长等属性
- 出现次数超过一半的数
- C语言结构体(struct)常见使用方法
- 轻轻的我走了,正如我轻轻的来——Duilib无焦点窗口的实现
- 设置UIButton的文字显示位置、字体的大小、字体的颜色
- const参数,const返回值与const函数
- 深入理解OutOfMemoryError
- 安全卫士——Day04_1