您的位置:首页 > 其它

安卓 保存Bitmap图片至本地并获得本地路径

2017-04-06 16:18 344 查看
public void saveBitmap(Bitmap bitmap) {
// 首先保存图片
File appDir = new File(Environment.getExternalStorageDirectory(),"zxing_image");
if (!appDir.exists()) {
appDir.mkdir();
}
String fileName = "zxing_image" + ".png";
file = new File(appDir, fileName);
try {
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
// 把文件插入到系统图库
try {
MediaStore.Images.Media.insertImage(this.getContentResolver(), file.getAbsolutePath(), fileName, null);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// 通知图库更新
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + "/sdcard/namecard/")));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐