BitmapをSDカードに保存
808 ワード
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();
}
}