android saves the Bitmap image to the specified folder example

  • 2020-05-17 06:21:55
  • OfStack

 
/**  Save method  */ 
public void saveBitmap() { 
Log.e(TAG, " Save the picture "); 
File f = new File("/sdcard/namecard/", picName); 
if (f.exists()) { 
f.delete(); 
} 
try { 
FileOutputStream out = new FileOutputStream(f); 
bm.compress(Bitmap.CompressFormat.PNG, 90, out); 
out.flush(); 
out.close(); 
Log.i(TAG, " Has been saved "); 
} catch (FileNotFoundException e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 
} catch (IOException e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 
} 
} 

Two more permissions are required here:
 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> 

Related articles: