AndroidでBitmap画像を保存
よく忘れるのでメモ書き。
ギャラリーに"/MyPhoto/"フォルダができてその中に保存されます。
最後のContentResolverの部分で保存したファイルパスを登録しておかないと、
デバイスを再起動するまでギャラリーが更新されない罠が準備されてます。
public void saveBitmap(Bitmap saveImage) throws IOException { final String SAVE_DIR = "/MyPhoto/"; File file = new File(Environment.getExternalStorageDirectory().getPath() + SAVE_DIR); try{ if(!file.exists()){ file.mkdir(); } }catch(SecurityException e){ e.printStackTrace(); throw e; } Date mDate = new Date(); SimpleDateFormat fileNameDate = new SimpleDateFormat("yyyyMMdd_HHmmss"); String fileName = fileNameDate.format(mDate) + ".jpg"; String AttachName = file.getAbsolutePath() + "/" + fileName; try { FileOutputStream out = new FileOutputStream(AttachName); saveImage.compress(CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch(IOException e) { e.printStackTrace(); throw e; } // save index ContentValues values = new ContentValues(); ContentResolver contentResolver = getContentResolver(); values.put(Images.Media.MIME_TYPE, "image/jpeg"); values.put(Images.Media.TITLE, fileName); values.put("_data", AttachName); contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); }