首页 > 代码库 > 将Bitmap保存为本地图片

将Bitmap保存为本地图片

public boolean saveMyBitmap(Bitmap bmp, String bitName) throws IOException {
boolean flag = false;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{

// 获得存储卡的路径
String sdpath = Environment.getExternalStorageDirectory() + "/";
String mSavePath = sdpath + "lzrc/imgs";

File f = new File(mSavePath, bitName);

f.createNewFile();
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
bmp.compress(Bitmap.CompressFormat.PNG, 100, fOut);
flag = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}

}
return flag;
}