首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

Android保留图片到数据库

2012-08-21 
Android保存图片到数据库?? ?闲话不多说,先看代码??? 方法一:import android.provider.MediaStore.Images.

Android保存图片到数据库

?? ?闲话不多说,先看代码

??? 方法一:

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);}
?

?

1 楼 feng88724 2011-10-18   也会保存到文件系统?

热点排行