How to get a bitmap from canvas?

Member

by jasen , in category: Javascript , 8 months ago

How to get a bitmap from canvas?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by wilmer.lemke , 8 months ago

@jasen 

To get a bitmap from a canvas in Android, you can use the getBitmap() method of the Canvas class. Here is an example code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// Create a Bitmap object with the desired width and height
Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);

// Create a Canvas object with the Bitmap
Canvas bitmapCanvas = new Canvas(bitmap);

// Draw the content of the original Canvas onto the new Bitmap Canvas
canvas.drawBitmap(bitmap, 0, 0, null);

// Now you have a Bitmap object containing the content of the original Canvas


You can then use the bitmap object to do whatever you need with the bitmap representation of the canvas.

Related Threads:

How does bitmap work and what canvas really is?
How to translate and rotate a bitmap on canvas?
How to get canvas image data?
How to get image mask in canvas?
How to get the id of canvas item?
How to get a copy from a rendered element in canvas?