Android tutorial: Save Bitmap image on Android SD Card

13 07 2013

Having the Bitmap or any other image, you can store it on the SD Card (or external device memory, if it doesn’t have SD Card). These are File and Stream operations. Here is complete code how to do it. Note that similar way you can store any other file type as well.

Bitmap Storage Source Code

Here the Bitmap image is stored on an ExternalStorageDirectory in ‘myAppDir/myImages/‘ subdirectory (it is created if it didn’t exist so far).

Image is saved as PNG. You can change it according to your image file extension to JPG or another.

private boolean storeImage(Bitmap imageData, String filename) {
	//get path to external storage (SD card)
	String iconsStoragePath = Environment.getExternalStorageDirectory() + "/myAppDir/myImages/"
	File sdIconStorageDir = new File(iconsStoragePath);

	//create storage directories, if they don't exist

	try {
		String filePath = sdIconStorageDir.toString() + filename;
		FileOutputStream fileOutputStream = new FileOutputStream(filePath);

		BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);

		//choose another format if PNG doesn't suit you
		imageData.compress(CompressFormat.PNG, 100, bos);


	} catch (FileNotFoundException e) {
		Log.w("TAG", "Error saving image file: " + e.getMessage());
		return false;
	} catch (IOException e) {
		Log.w("TAG", "Error saving image file: " + e.getMessage());
		return false;

	return true;

Image Access

Since this is stored on the SD Card, the file will be WORLD accessible by any app or by file explorer.

Storage Permissions

Since this is operation that saves data on external memory, it requires AndroidManifest.xml permissions:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!




6 responses

21 09 2013

It works for me. Great.

21 10 2013

When I will use this function

private boolean storeImage(Bitmap imageData, String filename)

What will be the parameter “Bitmap imageData”.

I have my image on my screen and I want to save it on my SD card. So I have no idea that How I pass as that parameter.

21 10 2013
Jacek Milewski

Any Bitmap object – I am really not able to guess what kind of Image you have. If your image is not a Bitmap, then google how to convert it.

26 02 2014

thanks man

13 06 2014

This worked for me as well!! Thx lad :D

23 05 2015
Hem Raj

this is working but when i click on image in my sd card it shows error….and image size is 0byte,how to solve it.

Give Your feedback:

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: