Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a bitmap into phone's gallery? [closed]

I take a photo and show it in an imageview. Then I get the bitmap from the imageview in my activity and when I press a button I want to save this bitmap into phone's gallery. What should I do?

like image 269
gulsen Avatar asked Feb 21 '23 23:02

gulsen


1 Answers

call this function in Button onClick

private void saveImage() {

  File myDir=new File("/sdcard/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();
  }
}

check this save bitmap

like image 157
RajaReddy PolamReddy Avatar answered Mar 04 '23 09:03

RajaReddy PolamReddy