android 保存图片到数据库
来源:互联网 发布:网上做账软件 编辑:程序博客网 时间:2024/06/04 19:53
方法一:
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:URI
Java代码
- import android.provider.MediaStore.Images.Media;
- 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);
- }
0 0
- android 保存图片到数据库
- android 保存图片到数据库
- Android:保存图片到Sqlite数据库
- android 将图片保存到数据库
- Android:保存图片到Sqlite数据库
- Android:保存图片到Sqlite数据库
- Android 保存图片到Sqlite数据库
- Android中将图片保存到数据库中
- 保存图片到数据库
- 保存图片到数据库
- 保存图片到数据库
- 保存图片到数据库
- 保存图片到数据库
- 保存图片到数据库
- 保存图片到数据库
- 图片保存到数据库
- 图片保存到数据库
- 图片保存到数据库
- Window文件目录挂载(mount)到linux系统目录下
- 装饰模式与代理模式的区别(转载)
- Unity (一)
- 老菜鸟的自留地
- Google浏览器 隐身模式 -incognito
- android 保存图片到数据库
- register_shutdown_function捕获致命错误
- JavaScript异常错误处理
- 为了IT,加强身体锻炼之【双盘腿打坐的好处】
- linux 远程桌面:SSH
- 只会左键断点?是时候试试这样那样断点了
- BCS和ECCS等合并系统简单对比
- Android.mk文档规范
- C++中常见的内存错误及其对策