5

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

onexf
  • 3,674
  • 3
  • 22
  • 36

2 Answers2

3

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

Saravanabalagi Ramachandran
  • 8,551
  • 11
  • 53
  • 102
2

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.

Sagar
  • 23,903
  • 4
  • 62
  • 62
Rakesh
  • 142
  • 2
  • 5
    this does not show how to insert the drawView.getCache image into specific directory (mFile). Can you show how to do that. Android documents are unclear, the insertImage method is overloaded to two kinds of methods, but both are unclear of how to do this. thanks – Ben Akin Oct 10 '16 at 23:22