首页 > 代码库 > 保存Bitmap到SD卡

保存Bitmap到SD卡

public static void saveBitmapInExternalStorage(Bitmap bitmap,Context context) {
		try {
			if(IsExternalStorageAvailableAndWriteable()) {
				File extStorage = new File(Environment.getExternalStorageDirectory().getPath() +"/orimuse");//orimuse为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();
		}
	}