public static void saveBitmapInExternalStorage(Bitmap bitmap,Context context) {
try {
if(IsExternalStorageAvailableAndWriteable()) {
File extStorage = new File(Environment.getExternalStorageDirectory().getPath() +"/test");//test为SD卡下一个文件夹
if (!extStorage.exists()) {
extStorage.mkdirs();
}
File file = new File(extStorage,System.currentTimeMillis()+".png");
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, fOut);//压缩图片
fOut.flush();
fOut.close();
Toast.makeText(context, "保存成功", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(context, "保存失败", Toast.LENGTH_SHORT).show();
}
}
catch (IOException ioe){
ioe.printStackTrace();
}
}
保存Bitmap到SD卡
最新推荐文章于 2021-05-27 02:29:24 发布