0

I have and activity where on click of menu item save I want to save the image of the screen to my device inside a a specific folder. how can I do it. ?

The image which is displayed in the background is a ImageView and the text is textview. I have to merge them and save them as a single image.

enter image description here

Community
  • 1
  • 1
Mayur
  • 789
  • 10
  • 37
  • what do u mean by merging?? and pls share the code where u tried doing it – Tushar Narang May 14 '14 at 11:35
  • I Mean to say is what ever is seen on the screen that is the image and the text, I want to store it as an image on the device – Mayur May 14 '14 at 11:38
  • Check this link: http://stackoverflow.com/questions/2661536/how-to-programatically-take-a-screenshot-on-android – Hulk May 14 '14 at 11:44

1 Answers1

1

Try with below code on menu item click event....

View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();

// give path of external directory to save image
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, "test.jpg");
FileOutputStream fos = null;

try {
    fos = new FileOutputStream(myPath);
    b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
    fos.flush();
    fos.close();       
} catch (Exception e) {       
    e.printStackTrace();
}

where view v is root layout...

Priyank Patel
  • 12,244
  • 8
  • 65
  • 85