Canvas Drawing

We know from the last chapter that we can draw Bitmap images on a Canvas object. That's not it for the Canvas class in Android, though. It also supports vector and text drawing. We can use a Canvas object either with Bitmap objects, as we did in the last chapter, or with Views. To start, we'll use a Canvas to create or alter a Bitmap and then move on to doing some very simple Canvas-based animation using a View.

Bitmap Creation

In the same manner we used previously, we can construct a Canvas object from a mutable Bitmap. To create a mutable Bitmap, a Bitmap that can be modified, we have to supply a width, a height, and a configuration. The configuration is generally a constant value defined in the Bitmap.Config class.

The following ...

Get Pro Android Media: Developing Graphics, Music, Video, and Rich Media Apps for Smartphones and Tablets 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.