Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MediaStore.Images.Media to save bitmap in particular folder

I have to save bitmap drawn on canvas to be saved in my own folder.

String imgSaved = MediaStore.Images.Media.insertImage(
                    getContentResolver(), drawView.getDrawingCache(),
                    UUID.randomUUID().toString() + ".png", "drawing"); 

How should i give a path to the directory? e.g. "/sdcard/MyPictures/"

like image 582
onexf Avatar asked Apr 07 '16 09:04

onexf


2 Answers

Use Bitmap.compress to save as JPG or PNG at desired location

File file = new File(yourpath, "yourfile.jpg");
FileOutputStream out = new FileOutputStream(filename);
yourbitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);

Note: 90 is the compression where 100 means no compression. It works for JPG and not for PNG. Don't forget to handle exceptions

like image 81
Saravanabalagi Ramachandran Avatar answered Oct 23 '22 14:10

Saravanabalagi Ramachandran


Try creating File object for your desired path

File mFile = new File("/sdcard/tmp");

String imgSaved=MediaStore.Images.Media.insertImage(getContentResolver(),mFile.getAbsolutePath(),UUID.randomUUID().toString()+".png", "drawing"); 

Check out this link for reference.

like image 2
Rakesh Avatar answered Oct 23 '22 16:10

Rakesh