0

I used this code to save the image:

mImageView.buildDrawingCache();
Bitmap bmap = mImageView.getDrawingCache();
OutputStream fOut = null;
Uri outputFileUri;
try {
    File root = new File(Environment.getExternalStorageDirectory()
    + File.separator + "folder_name" + File.separator);
    root.mkdirs();
    File sdImageMainDirectory = new File(root, "myPicName.jpg");
    outputFileUri = Uri.fromFile(sdImageMainDirectory);
    fOut = new FileOutputStream(sdImageMainDirectory);
           } 
catch (Exception e) {
            Toast.makeText(this, "Error occured. Please try again later.",
              Toast.LENGTH_SHORT).show();
           }

try {
            bmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
            fOut.flush();
            fOut.close();
           } 
catch (Exception e) {
           }

In this way the image is saved in the phone but is not visible in the phone gallery. How so? and then I wanted to know how to save to the internal memory instead of the sd card. Thanks.

davix10
  • 51
  • 1
  • 8
  • use this link it will help you. [LINK][1] [1]: http://stackoverflow.com/questions/20859584/how-save-image-in-android-gallery –  Apr 19 '14 at 15:19
  • I do not understand one thing. according to you because I see the pictures saved in the gallery, but only after about 20 minutes? – davix10 Apr 19 '14 at 19:00

1 Answers1

0

The simplest way to save Image to android Gallery is:

MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, imageTitle, imageDescriprion);

And add the android permission to your AndroidManifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
user3134124
  • 387
  • 4
  • 16