
安卓中如何获取保存的uri 并保存到sqlite数据库中
有如下两种方法,仅供参考
方法一:Java代码
public void saveIcon(Bitmap icon) {
if (icon == null) {
return;
}
// 最终图标要保存到浏览器的内部数据库中,系统程序均保存为SQLite格式,Browser也不例外,因为是二进制的所以使用字节数组存储数据库的
// BLOB类型
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// 将Bitmap压缩成PNG编码,质量为100%存储
iconcompress(BitmapCompressFormatPNG, 100, os);
// 构造SQLite的Content对象,这里也可以使用
raw ContentValues values = new ContentValues();
// 写入数据库的
BrowserBookmarkColumnsTOUCH_ICON字段 valuesput(BrowserBookmarkColumnsTOUCH_ICON, ostoByteArray());
DBUtilupdate();
//调用更新或者插入到数据库的方法
}
}
方法二:如果数据表入口时一个content:URIJava代码
import androidproviderMediaStoreImagesMedia;
import androidcontentContentValues;
import javaioOutputStream;
// Save the name and description of an image in a ContentValues map
ContentValues values = new ContentValues(3);
valuesput(MediaDISPLAY_NAME, "road_trip_1");
valuesput(MediaDESCRIPTION, "Day 1, trip to Los Angeles");
valuesput(MediaMIME_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(MediaEXTERNAL_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);
sourceBitmapcompress(BitmapCompressFormatJPEG, 50, outStream);
outStreamclose();
} catch (Exception e) {
Loge(TAG, "exception while writing image", e);
}
原文请看>
通过流的形式就可以了。通过路径得到文件流,然后使用bitmapfactorydecodeStream 方法 得到一个bitmap 然偶通过imageViewsetImageBitmap()就ok了
以上就是关于android 如何获取保存的图片的地址 并存到数据库中全部的内容,包括:android 如何获取保存的图片的地址 并存到数据库中、怎样解决android SQLite 图片是以图片的存储路径的方式存储的,读取并显示在GridVi.、android开发如何把数据库中图片路径转成图片读取显示等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)