onexf
onexf

Reputation: 3754

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/"

Upvotes: 5

Views: 17980

Answers (2)

Rakesh
Rakesh

Reputation: 152

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.

Upvotes: 2

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

Upvotes: 3

Related Questions