Android Graphics Class: Overview and Basic geometry drawing

Source: Internet
Author: User

When you need to draw graphics on Android, you'll use the graphics class, the Paint class. Paint is the equivalent of a pen, and canvas is

Paper, this is called the canvas.

So, all of the settings related to what you want to draw, such as size, weight, brush color, transparency, font style, etc., are

is set in the paint, similarly, anything that draws a finished product, such as a circle, rectangle, or text, is related to the canvas.

Yes.

Let's start with the basic setup function of paint:

Paint.setantialias (TRUE);//anti-aliasing function
Paint.setcolor (color.red); Set Brush color
Paint.setstyle (Style.fill);//Set Fill style
Paint.setstrokewidth (30);//Set Brush width
Paint.setshadowlayer (ten, Color.green);//Set Shadow

Top two nothing to say, look at the difference in the fill style:

1. void SetStyle (Paint.style style) set fill style

Paint.Style.FILL: Filling the interior
Paint.Style.FILL_AND_STROKE: Filling interior and stroke
Paint.Style.STROKE: Stroke only

2, Setshadowlayer (float radius, float dx, float dy, int color) Add Shadow

Parameters:

Radius: The tilt of the shadow
DX: Horizontal Displacement
DY: Vertical Displacement

Then the basic settings for the canvas are:

Canvas Background settings:

Canvas.drawcolor (Color.Blue);
Canvas.drawrgb (255, 255, 0); These two functions are all used to set the background color.

Second, basic geometry drawing

1. Draw a straight line

void DrawLine (float StartX, float starty, float stopx, float stopy, paint paint)

Parameters:

StartX: Start point x coordinate
Starty: Start point y coordinate
STOPX: End point x coordinate
Stopy: End point Y coordinate

2. Rectangle Tool class RECTF and rect

These two are rectangular auxiliary classes, the difference is not small, with any line, according to four points to construct a rectangular structure; When drawing, use this

The rectangle structure can draw the corresponding rectangle or intersect with other graphics region, add and so on.

RECTF:

The constructor has the following four, but the most commonly used is the second one, based on four points to construct a rectangle;

RECTF ()
RECTF (float left, float top, float right, float bottom)
RECTF (RECTF R)
RECTF (Rect R)


Rect

The constructor is as follows, and the most common is to construct a rectangle from four points

Rect ()
Rect (int left, int top, int. right, int bottom)
Rect (rect R)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Graphics Class: Overview and Basic geometry drawing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.