Using the Canvas class

Let's look at the code and the different stages required to get drawing, then we can quickly move on to drawing something for real with the Canvas demo app.

Preparing the instances of the required classes

The first step is to turn the classes we need into real, working things, objects/instances.

First we state the type, which in this case happens to be a class, and then we state the name we would like our working object to have:

// Here are all the objects(instances)
// of classes that we need to do some drawing
ImageView myImageView;
Bitmap myBlankBitmap;
Canvas myCanvas;
Paint myPaint;

The previous code declares reference type variables of the ImageView, Bitmap, Canvas, and Paint types. They are named myImageView, myBlankBitmap ...

Get Android Programming for Beginners - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.