2

I am creating an application that basically places a drawable into an imageView onClick. The result is a screen with a bunch of images on it in certain places. I want to save this screen as an image on the SD Card on the user's phone. I already know how to convert one imageView to a bitmap and save it to the SD Card, but how can I save all of the imageViews the way they are laid out on the screen as one file?

I have searched for an answer to this for several days. I was first thinking of programming in a button that would take a screenshot, but everything that I am reading says that you can only use screenshot on rooted phones.

Any help would be much appreciated. Thanks!

SillyFidget
  • 197
  • 3
  • 16

1 Answers1

2
Bitmap bitmap = findViewById(your_layout_id).getDrawingCache();
File file = new File(path_to_store_file);
if(!file.exists())    
    file.createNewFile();
try{
   FileOutputStream ostream = new FileOutputStream(file);
   bitmap.compress(CompressFormat.PNG, 100, (OutputStream)ostream);
 } 
catch (Exception e) 
{
    e.printStackTrace();
}
Ishu
  • 5,357
  • 4
  • 16
  • 17