1、Media是MediaStore的内部类
(MediaStore.Image.Media),它提供了几个insertImage方法,以方便我们想MediaStore插入图片数据,该操作会生成一张缩略图。插入有两个重载方法,一个是传入图片路径,一个是传入Bitmap;
区别:
传入图片路径的方法,会将制定的图片拷贝一份到Picture目录下,也就是SDCARD中共有两种相同的图片。
传入Bitmap的方法,会将图片直接保存到Picture目录下。
/**
* Insert an image and create a thumbnail for it.
*
* @param cr The content resolver to use
* @param imagePath The path to the image to insert
* @param name The name of the image
* @param description The description of the image
* @return The URL to the newly created image
* @throws FileNotFoundException
*/
public static final String insertImage(ContentResolver cr, String imagePath,
String name, String description) throws FileNotFoundException {
// Check if file exists with a FileInputStream
FileInputStream stream = new FileInputStream(imagePath);
try {
Bitmap bm = BitmapFactory.decodeFile(imagePath);
String ret = insertImage(cr, bm, name, description);
bm.recycle();
return ret;
} finally {
try {
stream.close();
} catch (IOException e) {
}
}
}