WassiM ZgheiB
WassiM ZgheiB

Reputation: 119

Saving an image on the mobile Android phone

I want to save an image that is received from an input stream to the device. This image is displayed using an ImageView and the function decodeStream().

How can I save the image received to a specific path (for instance, on the sdcard) on the mobile phone?

Upvotes: 1

Views: 268

Answers (2)

JRowan
JRowan

Reputation: 7104

make a bitmap also from decodestream say photo2

 mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
              Environment.DIRECTORY_PICTURES), "your apps name");   

 mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                 "Image" + num + ".png"); // make a int num and save it and
        try {                      //add it to the file name, increment for every
                                     //save that you do
            fOut = new FileOutputStream(mediaFile);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        photo2.compress(Bitmap.CompressFormat.PNG, 100,fOut);

Upvotes: 0

nedaRM
nedaRM

Reputation: 1827

To save to your external storage you can get the path like this:

Environment.getExternalStorageDirectory().toString();

Then when you're starting a Camera intent use this, file location can be any path.

camera.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, [file location]);

More info here: http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_OUTPUT

Upvotes: 1

Related Questions