开发者

Drawing a picture in android

开发者 https://www.devze.com 2023-01-06 22:32 出处:网络
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 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 exampl开发者_如何学Ce.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消