Paint,color,canvas
Paint: Brush object, paint with "pen"
Color: colour, equivalent to seasoning
Canvas: Canvases, cardboard in the real world
Paint brushes
The usual method is to set and get the style of the brush:
Paint. SetStyle(); Sets the style of the brush, hollow or solidPaint. SetColor(); Set the color of a brushPaint. Setstrokewidth(); Set the width of the border linePaint. Setalpha(); Set the alpha value of a brushPaint. Setantialias(); Set the brush's jagged effectPaint. Settextsize(); Set the size of the fontPaint. Getalpha(); Gets the alpha value of the brushPaint. GetColor(); Gets the color of the brushPaint. Gettextbounds(); Gets the smallest bounding rectangle that can contain fonts。。。。。。。
Color colors
Get the color you want by color name.
There are many common color enumeration values set in color, such as:
@ColorInt Public Static Final intBLACK =0xff000000;@ColorInt Public Static Final intDkgray =0xff444444;@ColorInt Public Static Final intGRAY =0xff888888;@ColorInt Public Static Final intLtgray =0xFFCCCCCC;@ColorInt Public Static Final intWhite =0xFFFFFFFF;@ColorInt Public Static Final intRED =0xffff0000;@ColorInt Public Static Final intGREEN =0xff00ff00;@ColorInt Public Static Final intBLUE =0xff0000ff;@ColorInt Public Static Final intYELLOW =0xffffff00;@ColorInt Public Static Final intCYAN =0xff00ffff;@ColorInt Public Static Final intMAGENTA =0xffff00ff;@ColorInt Public Static Final intTRANSPARENT =0;
Also, you can customize the color you want: Call Color.argb ()
/** * Return a color-int from alpha, red, green and blue components. * These component values should be [0..255], but there was no * range check performed, so if they was out of range, the * Returned color is undefined. * @param Alpha alpha component [0..255] of the The color * @param Red red Component [0..255] of the CO Lor * @param Green green Component [0..255] of the color * @param Blue blue component [0..255] of the color * / @ColorInt Public Static int ARGB(intAlphaintRedintGreenintBlue) {return(Alpha << -) | (Red << -) | (Green <<8) | Blue }
Canvas canvas, you can draw common graphics, such as circles, lines, rectangles draw straight lines: Canvas.drawline ();
/** * Draw a line segment with theSpecified start andStop x, y coordinates, * using theSpecified paint. * * <p>note that sinceA line isAlways"Framed", theStyle isIgnoredinch thepaint.</p> * * <p>degenerate lines (length is 0) would notBe drawn.</p> * * @param startX the X-coordinate of theStart point of theLine * @param starty the Y-coordinate of theStart point of theLine * @param paint the paint used toDraw theLine */public void **drawline** (float StartX, float starty, float stopx, float stopy, @NonNull Paint PA int
Draw Circle: Canvas.drawcircle ();
/** * Draw theSpecified circle using theSpecified paint. If radius is<=0, * ThenNothing would be drawn. The circle would be filledorFramed based * on theStyleinch thePaint. * * @param cx the X-coordinate of theCenter of theCirle toBe drawn * @param cy the Y-coordinate of theCenter of theCirle toBe drawn * @param radius the radius of theCirle toBe drawn * @param paint the paint used toDraw theCircle */public void **drawcircle** (float cx, float CY, float radius, @NonNull paint paint)
Draw rectangle:; Canvas.drawrect ();
/** * Draw theSpecified Rect using theSpecified paint. The rectangle would * be filledorFramed based on theStyleinch thePaint. * * @param left side of theRectangle toBe drawn * @param top the top side of theRectangle toBe drawn * @param right side of theRectangle toBe drawn * @param bottom the bottom side of theRectangle toBe drawn * @param paint the paint used toDraw theRECT */public void **drawrect** (float-left, float-top, float right, float bottom, @NonNull paint paint)
Draw Picture: Canvas.drawbitmap ();
/** * Draw theSpecified bitmap, with itsTop/left Corner at(x, y), using * theSpecified paint, transformed by theCurrent matrix. * * <p>note:if thePaintcontainsA maskfilter thatGenerates a mask which * extends beyond theBitmap ' s original width/height (e.g. blurmaskfilter), * Then theBitmap'll be drawn as if itWereinchA Shader withCLAMP mode. * Thus theColor outside of theOriginal Width/height'll be theEdge * Color replicated. * * <p>if theBitmap andCanvas has different densities, this function * would take care ofAutomatically scaling theBitmap toDraw at the* Same density as theCanvas. * * @param bitmap the bitmap toBe drawn * @param left the position of theLeft side of theBitmap being drawn * @param top the position of theTop side of theBitmap being drawn * @param paint the paint used toDraw theBitmap (may be null) */public void **drawbitmap** (@NonNull bitmap bitmap, float left, float top, @Nullable Paint p Aint) {Throwifcannotdraw (bitmap)
Draw text: Canvas.drawtext ();
/** * Draw the text, withOrigin at(x, y), using theSpecified paint. The * origin isInterpreted based on theAlign settinginch thePaint. * * @paramtextThetext toBe drawn * @param x the X-coordinate of theOrigin of the textBeing drawn * @param y the Y-coordinate of theBaseline of the textBeing drawn * @param paint the paint used for the text(e.g. color, size, style) */public void **drawtext** (@NonNull Stringtext, float x, float y, @NonNull paint paint)
Draw arc: Canvas.drawarc ();
/** * <p>draw theSpecified arc, which'll be scaled toFit inside the* Specified oval.</p> * * <p>if theStart angle isNegativeor>= the, theStart angle isTreated * asStart angle modulo.</p> * * <p>if theSweep angle is>= the, Then theOval isDrawn * completely. Note thatThis differs slightly fromSkpath::arcto, which * treats theSweep angle modulo.If theSweep angle isNegative, * theSweep angle isTreated asSweep angle modulo the</p> * * <p>the arc isDrawn clockwise. An angle of 0degrees correspond to the* Geometric angle of 0Degrees (3O ' clock onA watch.) </p> * * @param oval the Bounds ofOval used toDefine theShape andSize * of theARC * @param startangle starting angle (inchDegreeswhere theArc begins * @param sweepAngle Sweep Angle (inchdegrees) measured clockwise * @param usecenter Iftrue, include theCenter of theOvalinch theArc andCloseit if it isBeing stroked. This would draw a wedge * @param paint the paint used toDraw theARC */public void **drawarc** (@NonNull rectf Oval, float startangle, float sweepAngle,BooleanUsecenter, @NonNull paint paint)
。。。。。。。
Summary
Customizing the view usually overrides the OnDraw () method, the three elements necessary for drawing: Color,paint,canvas
Set the brush's style setting color to draw on the canvas
Custom three object parsing (Paint,color,canvas) in Android