Created
July 9, 2014 01:47
-
-
Save kenmasumitsu/dfed8d989d9df3586a0e to your computer and use it in GitHub Desktop.
Save Bitmap as a file in SD card
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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