Skip to content

Instantly share code, notes, and snippets.

@devapro
Created November 13, 2024 23:58
Show Gist options
  • Select an option

  • Save devapro/90c8adbe26e14f368baeb2299151e73d to your computer and use it in GitHub Desktop.

Select an option

Save devapro/90c8adbe26e14f368baeb2299151e73d to your computer and use it in GitHub Desktop.
Android view get bitmap
// Android view get bitmap
private ImageBitmap getBitmapFromViewUsingCanvas(View view) {
// Create a new Bitmap object with the desired width and height
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
// Create a new Canvas object using the Bitmap
Canvas canvas = new Canvas(bitmap);
// Draw the View into the Canvas
view.draw(canvas);
// Return the resulting Bitmap
return asImageBitmap(bitmap);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment