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
, myCanvas
, and myPaint
, respectively.
Initializing the objects
Next, we need to initialize our new objects before using them:
// Initialize all the objects ready for drawing // We will do this inside the onCreate method int widthInPixels =...