Skip to content

Instantly share code, notes, and snippets.

@GBouerat
Last active November 24, 2022 16:32
Show Gist options
  • Save GBouerat/6305151 to your computer and use it in GitHub Desktop.
Save GBouerat/6305151 to your computer and use it in GitHub Desktop.
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();
}
@GBouerat
Copy link
Author

Android : save a View to a Bitmap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment