Android Drawable Concepts

How to correctly understand the concept of classes Canvas, Drawable, Bitmap and Paint? What is the relationship between them?

Can someone please give an example?

Thank you very much.

+4
source share
3 answers

Please visit the link. It can help you.

+1
source

In the Canvas class document :

In the Canvas class, “drawing” calls are performed. To draw something, you need 4 main components: a bitmap for pixels, a canvas for placing anyone’s calls (writing to a bitmap), (for example, Rect, Path, text, bitmap) and paint (to describe the colors and styles for drawing).

So, you need 4 components to draw something.

  • Raster
  • Canvas
  • Drawable
  • Paint

Suppose you want to draw a circle on a background image from your available folder.

Canvas canvas; Bitmap mBG; Paint mPaint = new mPaint(); mBG = BitmapFactory.decodeResource(res, R.drawable.apple); //Return a bitmap from the image from drawable folder Canvas.drawBitmap(mBG, 0,0, null); //Draw the bitmap mPaint.setColor(Color.BLACK); //Set paint to BLACK color Canvas.drawCircle(100,100,30, mPaint); //Draw circle at coordinate x:100,y:100, radius 30 with the paint defined 
+6
source

The official Android documentation contains all the details about the API. And the best way to learn something is learning, so by reading docs, google for tutorials and experimenting, all your doubts will be gradually eliminated.

Canvas

Drawable

Bitmap

Paint

+4
source

Source: https://habr.com/ru/post/1346182/


All Articles