First, you need to get a bitmap. You can already use it as a Bitmap object, or you can try to get it from ImageView, for example:
BitmapDrawable drawable = (BitmapDrawable) mImageView1.getDrawable(); Bitmap bitmap = drawable.getBitmap();
Then you should go to the directory (a File object) from the SD card, for example:
File sdCardDirectory = Environment.getExternalStorageDirectory();
Then create your image storage file:
File image = new File(sdCardDirectory, "test.png");
After that, you just need to write Bitmap thanks to its compress method, for example:
boolean success = false;
Finally, if necessary, process the logical result. For example:
if (success) { Toast.makeText(getApplicationContext(), "Image saved with success", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "Error during image saving", Toast.LENGTH_LONG).show(); }
Remember to add the following permission to your manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Romain R.
source share