private static File mPhotoFile = null;
public static void setPhotoFile(File photoFile){
mPhotoFile = photoFile;
}
public static File getPhotoFile(){
return mPhotoFile;
}
/**
* @param bmp 獲取的bitmap數(shù)據(jù)
* @param picName 自定義的圖片名
*/
public static void saveBmp2Gallery(Context context,Bitmap bmp, String picName) {
// saveImageToGallery(bmp,picName);
String fileName = null;
//系統(tǒng)相冊目錄
String galleryPath = Environment.getExternalStorageDirectory()
+ File.separator + Environment.DIRECTORY_DCIM
+ File.separator + "Camera" + File.separator;
// + File.separator + "yingtan" + File.separator;
// String photoName = System.currentTimeMillis() + ".jpg";
// 聲明文件對象
File file = null;
// 聲明輸出流
FileOutputStream outStream = null;
try {
// 如果有目標文件,直接獲得文件對象岂昭,否則創(chuàng)建一個以filename為名稱的文件
file = new File(galleryPath, picName + ".jpg");
// file = new File(galleryPath, photoName);
// 獲得文件相對路徑
fileName = file.toString();
// 獲得輸出流,如果文件中有內(nèi)容擂橘,追加內(nèi)容
outStream = new FileOutputStream(fileName);
if (null != outStream) {
bmp.compress(Bitmap.CompressFormat.JPEG, 90, outStream);
}
}catch (Exception e) {
e.getStackTrace();
} finally {
try {
if (outStream != null) {
outStream.close();
setPhotoFile(file);
}
} catch (IOException e) {
e.printStackTrace();
}
}
try {
// MediaStore.Images.Media.insertImage(context.getContentResolver(),file.getAbsolutePath(),fileName,null);
MediaStore.Images.Media.insertImage(context.getContentResolver(),bmp,fileName,null);
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(file);
intent.setData(uri);
context.sendBroadcast(intent);
ToastUtils.showToast(context,"圖片保存成功");
} catch (Exception e) {
e.printStackTrace();
ToastUtils.showToast(context,"圖片保存失敗");
}
}
android 中實現(xiàn)保存圖片到系統(tǒng)相冊中
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門搀崭,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人猾编,你說我怎么就攤上這事瘤睹。” “怎么了答倡?”我有些...
- 文/不壞的土叔 我叫張陵默蚌,是天一觀的道長。 經(jīng)常有香客問我苇羡,道長绸吸,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任设江,我火速辦了婚禮锦茁,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘叉存。我一直安慰自己码俩,他們只是感情好倦淀,可當我...
- 文/花漫 我一把揭開白布宾巍。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪才睹。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼辜贵,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了归形?” 一聲冷哼從身側(cè)響起托慨,我...
- 正文 年R本政府宣布菩貌,位于F島的核電站卢佣,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏箭阶。R本人自食惡果不足惜虚茶,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望仇参。 院中可真熱鬧嘹叫,春花似錦、人聲如沸诈乒。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽怕磨。三九已至喂饥,卻和暖如春消约,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背员帮。 一陣腳步聲響...