Last active
November 24, 2022 16:32
-
-
Save GBouerat/6305151 to your computer and use it in GitHub Desktop.
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
public static void screenshot(View view, String path) throws Exception { | |
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); | |
Canvas canvas = new Canvas(bitmap); | |
view.draw(canvas); | |
File file = new File(path); | |
file.mkdirs(); | |
file = new File(path, "screenshot_" + System.currentTimeMillis() + ".png"); | |
FileOutputStream fileOutputStream = new FileOutputStream(file); | |
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream); | |
fileOutputStream.close(); | |
bitmap.recycle(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Android : save a View to a Bitmap