// 将Bitmap保存为文件File的方法
private File saveAvatar(Bitmap bitmap,String filename) {
try {
String dirPath = Environment.getExternalStorageDirectory()
.getAbsolutePath();
Log.i("tag", "头像路径dirpath=="+dirPath+Constants.SAVE_GOODS_IMAGE);///storage/emulated/0
File file=new File(dirPath, filename);
fileOutputStream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, fileOutputStream);
return file;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(fileOutputStream!=null){
try {
fileOutputStream.flush();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
private File saveAvatar(Bitmap bitmap,String filename) {
try {
String dirPath = Environment.getExternalStorageDirectory()
.getAbsolutePath();
Log.i("tag", "头像路径dirpath=="+dirPath+Constants.SAVE_GOODS_IMAGE);///storage/emulated/0
File file=new File(dirPath, filename);
fileOutputStream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, fileOutputStream);
return file;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(fileOutputStream!=null){
try {
fileOutputStream.flush();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}