方法一:
Java代码
public void saveIcon(Bitmap icon) {
if (icon == null) {
return;
}
// 最终图标要保存到浏览器的内部数据库中,系统程序均保存为SQLite格式,Browser也不例外,因为图片是二进制的所以使用字节数组存储数据库的
// BLOB类型
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// 将Bitmap压缩成PNG编码,质量为100%存储
icon.compress(Bitmap.CompressFormat.PNG, 100, os);
// 构造SQLite的Content对象,这里也可以使用raw
ContentValues values = new ContentValues();
// 写入数据库的Browser.BookmarkColumns.TOUCH_ICON字段
values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray());
DBUtil.update(....);//调用更新或者插入到数据库的方法
}
方法二:如果数据表入口时一个content:URIimport android.provider.MediaStore.Images.Media;
Java代码
import android.content.ContentValues;
import java.io.OutputStream;
// Save the name and description of an image in a ContentValues map.
ContentValues values = new ContentValues(3);
values.put(Media.DISPLAY_NAME, "road_trip_1");
values.put(Media.DESCRIPTION, "Day 1, trip to Los Angeles");
values.put(Media.MIME_TYPE, "image/jpeg");
// Add a new record without the bitmap, but with the values just set.
// insert() returns the URI of the new record.
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
// Now get a handle to the file for that record, and save the data into it.
// Here, sourceBitmap is a Bitmap object representing the file to save to the database.
try {
OutputStream outStream = getContentResolver().openOutputStream(uri);
sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
outStream.close();
} catch (Exception e) {
Log.e(TAG, "exception while writing image", e);
}
import android.content.ContentValues;
import java.io.OutputStream;
// Save the name and description of an image in a ContentValues map.
ContentValues values = new ContentValues(3);
values.put(Media.DISPLAY_NAME, "road_trip_1");
values.put(Media.DESCRIPTION, "Day 1, trip to Los Angeles");
values.put(Media.MIME_TYPE, "image/jpeg");
// Add a new record without the bitmap, but with the values just set.
// insert() returns the URI of the new record.
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
// Now get a handle to the file for that record, and save the data into it.
// Here, sourceBitmap is a Bitmap object representing the file to save to the database.
try {
OutputStream outStream = getContentResolver().openOutputStream(uri);
sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
outStream.close();
} catch (Exception e) {
Log.e(TAG, "exception while writing image", e);
}
转载:http://sanfeng-chow.iteye.com/blog/599350
分享到:
相关推荐
SqlLite中保存图片,非常简单易学,将图片转换保存,然后显示
try{ /* 初始化并创建数据库 */ dbHelper = new SQLiteHelper(this, DB_NAME, null, DB_VERSION); /* 创建表 */ db = dbHelper.getWritableDatabase(); //调用SQLiteHelper.OnCreate() ...
sqllite加密与解密存储,结合himi加密方法
sqllite 使用
sqllite加密工具,直接在winform中使用。可清除加密字符
sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言
安卓开发的简单的sqllite本机存储数据的小示例
delphi的SQLLite 控件,支持D5~D10,SQLLite为开源的数据库
Android 使用sqllite 实现listView上拉加载,简单易懂,适合新手学习sqllite以及自定义listview
SQLlite数据库
SQLLite 超详细SQLLite 超详细SQLLite 超详细
SQLLite-Official NuGet Packages .NET下使用的SQLLite-Official NuGet Packages 版本:3.8.2
包含API、SqlLite3、sqlitestudio-2.1.2
SQLlite数据库.rar
sqllite小型开发项目数据库,官方没有这样的工具,这个很适用
一个小巧的sqllite数据库,可以用来执行sql语句,管理.db的数据文件。
sqllite跨平台管理工具 很好很强大
SQLlite简单教程
Delphi操作SQLLite数据库,实战演习
文件数据库 SQLLITE 文件数据库 SQLLITE 文件数据库 SQLLITE