Android Graphics class: Overview and basic geometric drawing, androidgraphics
When you need to draw images on Android, the Graphics class and the Paint class are used. Painting is equivalent to a pen, while Canvas is
The canvas.
Therefore, all settings related to the things to be painted, such as the size, width, paint color, transparency, and font style are
Is set in the Paint; similarly, all the things that need to draw finished products, such as circles, rectangles, and texts, are generated in the Canvas.
.
The following describes the basic setting function of Paint:
Paint. setAntiAlias (true); // anti-aliasing Function
Paint. setColor (Color. RED); // you can specify the paint Color.
Paint. setStyle (Style. FILL); // you can specify a filling Style.
Paint. setStrokeWidth (30); // you can specify the paint width.
Paint. setShadowLayer (10, 15, 15, Color. GREEN); // sets the shadow.
There is nothing to say about the first two. Let's look at the difference between fill styles:
1. void setStyle (Paint. Style style) to set the fill Style
Paint. Style. FILL: internal filling
Paint. Style. FILL_AND_STROKE: Fill the interior and stroke
Paint. Style. STROKE: STROKE only
2. Add shadowlayer (float radius, float dx, float dy, int color) to the shadow.
Parameters:
Radius: the slope of the shadow.
Dx: horizontal displacement
Dy: vertical displacement
The basic settings of Canvas are as follows:
Canvas background settings:
Canvas. drawColor (Color. BLUE );
Canvas. drawRGB (255,255, 0); // both functions are the same and are used to set the background color.
Ii. Basic geometric drawing
1. draw a straight line
Void drawLine (float startX, float startY, float stopX, float stopY, Paint)
Parameters:
StartX: start point X coordinate
StartY: Y coordinate of start point
StopX: coordinates of the end point X
StopY: Y coordinate of the end point
2. RectF and Rect for rectangular tools
These two are rectangular auxiliary classes, which are slightly different. You can create a rectangular structure based on the four points.
The rectangle structure can draw the corresponding rectangle or intersect and add with other images;
RectF:
There are four constructors, but the second one is most commonly used. A rectangle is constructed based on the four points;
RectF ()
RectF (float left, float top, float right, float bottom)
RectF (RectF r)
RectF (Rect r)
Rect
The constructor is as follows. The most common method is to construct a rectangle based on four points.
Rect ()
Rect (int left, int top, int right, int bottom)
Rect (Rect r)
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.