Skip to content

Instantly share code, notes, and snippets.

@donrokzon
Created March 12, 2018 06:56
Show Gist options
  • Select an option

  • Save donrokzon/ee3f773fa959e2d6bdb487b7b0cdac62 to your computer and use it in GitHub Desktop.

Select an option

Save donrokzon/ee3f773fa959e2d6bdb487b7b0cdac62 to your computer and use it in GitHub Desktop.
Screenshot
void saveAsImage(){
View content = getActivity().findViewById(R.id.rootLayout);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file = new File("/sdcard/" + "demo" + ".png");
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 10, ostream);
ostream.close();
content.invalidate();
} catch (Exception e) {
e.printStackTrace();
} finally {
content.setDrawingCacheEnabled(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment