I want to draw a picture (bmp,jpg,png) into the canvas (using the onDraw() method) of a class that extends the View class. I would like to be able to draw parts of the picture, not the whole at once.
I would really appreciate an example.
I want to draw a picture (bmp,jpg,png) into the canvas (using the onDraw() method) of a class that extends the View class. I would like to be able to draw parts of the picture, not the whole at once.
I would really appreciate an example.
Hi,
You must first realize where the image is located. It can be bundled in your application in res/ or assets/ directory; or it can be loaded from SD card or internet. That will determine the way you'll obtain a Bitmap object, representing your image. If you distribute the image along with your application, place it in res/ or assets/ directory of your project. The difference is how you refer to the file - when in res/ you use R.drawable. id-s, when in assets/ you use filename.
To draw a portion of a Bitmap object on a Canvas, call the drawBitmap method.