Using the Canvas class
Let's take a look at the code and the different stages that are 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 that we need into usable instances.
First, we declare all the instances that we require. We can't initialize the instances right away, but we can make sure that we initialize them before they are used, so we use lateinit
in the same way we did in the Animation demo app:
// Here are all the objects(instances) // of classes that we need to do some drawing lateinit var myImageView: ImageView lateinit var myBlankBitmap: Bitmap lateinit var myCanvas: Canvas lateinit var myPaint: Paint
The previous code declares references 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...