圖片路徑爲根目錄/a1/時間戳.jpg
public File saveBitmap(Bitmap bitmapUse) {
Log.e("wy", "開始保存");
//生成一個文件,存儲我們將來拍照的照片
String sdPath = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/a1";
File file = new File(sdPath);
Log.e("wy","絕對文件路徑: "+ file.getAbsoluteFile());
Log.e("wy","文件名: "+ file.getName());
if (!file.exists()) {
file.mkdirs();
Log.e("wy", "創建文件夾,路徑:"+file.getPath());
}
String mPath = System.currentTimeMillis() + "";
Log.e("wy", "保存路徑: " + sdPath);
File f = new File(sdPath, mPath + ".jpg");
// File f = new File("/sdcard/namecard/", picName);
if (f.exists()) {
f.delete();
}
try {
FileOutputStream out = new FileOutputStream(f);
// 10M
// bitmapUse.compress(Bitmap.CompressFormat.PNG, 90, out);
// 0.5M
bitmapUse.compress(Bitmap.CompressFormat.JPEG, 45, out);
out.flush();
out.close();
Log.e("wy", "已經保存");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return f;
}