Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an empty bitmap and drawing though canvas in Android

I'd like to create an empty bitmap and set a canvas to that bitmap and then draw any shape on the bitmap.

like image 820
Sunil Pandey Avatar asked Apr 14 '11 13:04

Sunil Pandey


People also ask

How do I know if my Android BMP is empty?

You can do a check when you want to return the BitMap look to see if the ArrayList of Paths is bigger than 0 and return the BitMap if so, or else return null.

What is bitmap in canvas?

Canvas is the place or medium where perfroms/executes the operation of drawing, and Bitmap is responsible for storing the pixel of the picture you draw.


1 Answers

This is probably simpler than you're thinking:

int w = WIDTH_PX, h = HEIGHT_PX;  Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap Canvas canvas = new Canvas(bmp);  // ready to draw on that bitmap through that canvas 

Here's a series of tutorials I've found on the topic: Drawing with Canvas Series

like image 80
bigstones Avatar answered Sep 21 '22 03:09

bigstones