Created
March 12, 2018 06:56
-
-
Save donrokzon/ee3f773fa959e2d6bdb487b7b0cdac62 to your computer and use it in GitHub Desktop.
Screenshot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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