0

I have the bitmap image that I got from my camera activity. Can someone please guide me as to how can I store this image in the gallery?

code:

In my button OnClickListener

    Intent campic=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(campic,cameradata ); 

In my onActivityResult

        if(resultCode==RESULT_OK)
        {
           Bundle bun=data.getExtras();
           bmp=(Bitmap)bun.get("data");
           SaveIamge(bmp);
           iveventpic.setImageBitmap(bmp);
        }
Nemin Shah
  • 217
  • 1
  • 3
  • 15
  • [This link][1] is probably what you're looking for. [1]: http://stackoverflow.com/questions/8560501/android-save-image-into-gallery – Tom Apr 25 '13 at 01:43
  • if you save to gallery it wont show up until the next time you turn your phone on uless you sendBroadcast(new Intent( Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); – JRowan Apr 25 '13 at 01:45

2 Answers2

0
MediaStore.Images.Media.insertImage(getContentResolver(), bmp, title, desc);

As seen in this post.

Community
  • 1
  • 1
Tom
  • 340
  • 1
  • 7
0

call this function to save bitmap in sdcard:

private void SaveIamge(Bitmap finalBitmap) {

String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/saved_images");    
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete (); 
try {
       FileOutputStream out = new FileOutputStream(file);
       finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
       out.flush();
       out.close();

} catch (Exception e) {
       e.printStackTrace();
}
}

By calling this line u have to store that image in the gallery:

sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
        Uri.parse("file://" + Environment.getExternalStorageDirectory())));

and Add permission in the manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
SubbaReddy PolamReddy
  • 2,083
  • 2
  • 17
  • 23
  • It worked :) But the gallery does not show the image immedietely. Is is that the gallery is refereshed after a fixed interval? – Nemin Shah Apr 28 '13 at 16:19