Creating bitmaps
Let's do a little bit of theory before we dive into the code and consider exactly how we are going to bring images to life on the screen. To draw a bitmap, we will use the drawBitmap method of the Canvas class.
First, we would need to add a bitmap to the project in the res/drawable folder; we will do this for real in the Bitmap demo app coming up shortly. For now, assume the graphics file/bitmap has the name myImage.png.
Next, we declare an object of the Bitmap type, just the same as we did for the Bitmap object we used for our background in the previous demo:
Bitmap mBitmap;
Next, we need to initialize the mBitmap object using our preferred image that we previously added to the project's drawable folder:
mBitmap = BitmapFactory.decodeResource (getResources(), R.drawable.myImage);
The static decodeResource method of the BitmapFactory method is...