Take the 2-minute tour ×

i am trying to coding an apllication to get an image from gallery then do some effects oon it, and after showing the image, i want to save it as JPG in SdCard. can any on plz thell me how to save image on sdcard, and where should i put save code? this is where i want to save, after clicking on button2:

public void onClick(View arg0) {
                    Bitmap yourimage;
                    ImageButton effected=(ImageButton)findViewById(R.id.imageButton2);
                    int width = 150;
                    int height =150; 
                    Bitmap resizedbitmap=Bitmap.createScaledBitmap(yourimage, width, height, true);

i mean after set image as resizedbitmap i want to save it in sdcard

share|improve this question
Possible duplicate, or at least includes several possible answers: stackoverflow.com/questions/649154/… –  Mehmet M. Inanc Sep 8 '12 at 23:20
If/When answers work you need to accept them. –  WIllJBD Sep 21 '12 at 22:04
add comment

2 Answers

up vote 2 down vote accepted

this is basically it

Bitmap bmp = createBitmap();
OutputStream stream = new FileOutputStream("/sdcard/test.jpg");
bmp.compress(CompressFormat.JPEG, 100, stream);
share|improve this answer
add comment

If You have an image in bitmpa formate, for example if you take a screen shot of your apps and now you want to store that bitmap image object as an image file in sdcard in "jpg" format, then use this few line of code, hope you will get your answer.

//----------- Store the image file in sdcard with image file name..-------

  OutputStream fOut = null;
 File file = new File("sdcard/pir_fahim_shah.jpg");
        fOut = new FileOutputStream(file);
         b.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
         catch (IOException e) 
        {   e.printStackTrace();  }
        } catch (FileNotFoundException e) 
          {     e.printStackTrace();    }

 try {
 catch (FileNotFoundException e) 
{     e.printStackTrace();   }
share|improve this answer
add comment

Your Answer


