Skip to content

Instantly share code, notes, and snippets.

@kenmasumitsu
Created July 9, 2014 01:47
Show Gist options
  • Save kenmasumitsu/dfed8d989d9df3586a0e to your computer and use it in GitHub Desktop.
Save kenmasumitsu/dfed8d989d9df3586a0e to your computer and use it in GitHub Desktop.
Save Bitmap as a file in SD card
void saveBitmapToSd(Bitmap mBitmap) {
try {
// sdcardフォルダを指定
File root = Environment.getExternalStorageDirectory();
// 日付でファイル名を作成 
Date mDate = new Date();
SimpleDateFormat fileName = new SimpleDateFormat("yyyyMMdd_HHmmss");
// 保存処理開始
FileOutputStream fos = null;
fos = new FileOutputStream(new File(root, fileName.format(mDate) + ".jpg"));
// jpegで保存
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
// 保存処理終了
fos.close();
} catch (Exception e) {
Log.e("Error", "" + e.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment