53. Introduction to Android Canvas Paint
Android Canvas Paint
Canvas
Crop the canvas:
Region. op. INTERSECT returns the intersection of the two. The default method is Region. op. DIFFERENCE first minus the second intersection Region. op. REPLACE shows the second Region. op. REVERSE_DIFFERENCE minus the first intersection Region. op. UNION returns the complete set of Region. op. XOR is used to retrieve the complete set, that is, to display the remainder of the complete set minus the intersection.
clipPath(Path path)
clipPath(Path path, Region.Op op)
clipRect(Rect rect, Region.Op op)
clipRect(RectF rect, Region.Op op)
clipRect(int left, int top, int right, int bottom)
clipRect(float left, float top, float right, float bottom)
clipRect(RectF rect)
clipRect(float left, float top, float right, float bottom, Region.Op op)
clipRect(Rect rect)
clipRegion(Region region)
clipRegion(Region region, Region.Op op)
Transformation Matrix:
concat(Matrix matrix)
Draw an arc
drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
drawArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
Draw Bitmap
drawBitmap(int[] colors, int offset, int stride, float x, float y, int width, int height, boolean hasAlpha, Paint paint)
drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint)
drawBitmap(int[] colors, int offset, int stride, int x, int y, int width, int height, boolean hasAlpha, Paint paint)
drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)
drawBitmap(Bitmap bitmap, float left, float top, Paint paint)
drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
Plot Bitmap Distortion
drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, int vertOffset, int[] colors, int colorOffset, Paint paint)
Draw a circle
drawCircle(float cx, float cy, float radius, Paint paint)
Draw background
drawARGB(int a, int r, int g, int b)
drawColor(int color)
drawColor(int color, PorterDuff.Mode mode)
drawPaint(Paint paint)
drawRGB(int r, int g, int b)
Draw lines
drawLine(float startX, float startY, float stopX, float stopY, Paint paint)
drawLines(float[] pts, Paint paint)
drawLines(float[] pts, int offset, int count, Paint paint)
Draw an ellipse
drawOval(float left, float top, float right, float bottom, Paint paint)
drawOval(RectF oval, Paint paint)
Draw path, which can draw any Polygon
drawPath(Path path, Paint paint)
Draw Images
drawPicture(Picture picture, RectF dst)
drawPicture(Picture picture)
drawPicture(Picture picture, Rect dst)
Draw point
drawPoint(float x, float y, Paint paint)
drawPoints(float[] pts, int offset, int count, Paint paint)
drawPoints(float[] pts, Paint paint)
Draw text to specify the position of each text
drawPosText(char[] text, int index, int count, float[] pos, Paint paint)
drawPosText(String text, float[] pos, Paint paint)
Draw a rectangle
drawRect(float left, float top, float right, float bottom, Paint paint)
drawRect(RectF rect, Paint paint)
drawRect(Rect r, Paint paint)
Draw rounded rectangle
drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint)
drawRoundRect(RectF rect, float rx, float ry, Paint paint)
Draw text
drawText(String text, float x, float y, Paint paint)
drawText(CharSequence text, int start, int end, float x, float y, Paint paint)
drawText(char[] text, int index, int count, float x, float y, Paint paint)
drawText(String text, int start, int end, float x, float y, Paint paint)
Text drawn on the path
drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint)
drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, float vOffset, Paint paint)
Specify the position and size of the text to be drawn.
drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, float x, float y, boolean isRtl, Paint paint)
drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, float x, float y, boolean isRtl, Paint paint)
Draw vertex data or distorted images
drawVertices(Canvas.VertexMode mode, int vertexCount, float[] verts, int vertOffset, float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices, int indexOffset, int indexCount, Paint paint)
Obtains the rectangle intercepted on the Canvas.
getClipBounds()
getClipBounds(Rect bounds)
Obtains the pixel density of the Canvas.
getDensity()
Get canvas Filter
getDrawFilter()
Get canvas width and height
getHeight()
getWidth()
Obtain the canvas Matrix
getMatrix(Matrix ctm)
getMatrix()
Obtains the maximum allowed height and width of a Bitmap canvas.
getMaximumBitmapHeight()
getMaximumBitmapWidth()
Returns the matrix or number of private stack states on the canvas.
getSaveCount()
Hardware acceleration?
isHardwareAccelerated()
Not transparent?
isOpaque()
Save the current canvas status.
save()
save(int saveFlags)
Similar to save (), create a new layer on the current layer and call restore to restore the original status.
saveLayer(RectF bounds, Paint paint, int saveFlags)
saveLayer(RectF bounds, Paint paint)
saveLayer(float left, float top, float right, float bottom, Paint paint)
saveLayer(float left, float top, float right, float bottom, Paint paint, int saveFlags)
saveLayerAlpha(RectF bounds, int alpha, int saveFlags)
saveLayerAlpha(RectF bounds, int alpha)
saveLayerAlpha(float left, float top, float right, float bottom, int alpha, int saveFlags)
saveLayerAlpha(float left, float top, float right, float bottom, int alpha)
Retrieve the status of the last save
restore()
restoreToCount(int saveCount)
Canvas flip
translate(float dx, float dy)
Canvas Rotation
rotate(float degrees)
rotate(float degrees, float px, float py)
Canvas Scaling
scale(float sx, float sy)
scale(float sx, float sy, float px, float py)
Create a canvas using Bitmap
setBitmap(Bitmap bitmap)
Set canvas pixel density
setDensity(int density)
Set canvas Filter
setDrawFilter(DrawFilter filter)
Set canvas Matrix
setMatrix(Matrix matrix)
Set canvas Distortion
skew(float sx, float sy)
Paint
Set color and transparency
setARGB(int a, int r, int g, int b)
Set transparency
setAlpha(int a)
Set anti-aliasing
setAntiAlias(boolean aa)
Set color
setColor(int color)
Image jitter processing: The image color is smoother and Fuller, and the image is clearer.
setDither(boolean dither)
True: the Bitmap image is filtered out during the animation to accelerate the display speed. It depends on the settings of dither and xfermode.
setFilterBitmap(boolean filter)
Set MaskFilter to implement filter effect
setMaskFilter(MaskFilter maskfilter)
Set the color filter to achieve the effect of no color conversion when drawing the color.
setColorFilter(ColorFilter colorfilter)
Set the effect of the draw path, such as drawing a line.
setPathEffect(PathEffect effect)
Set the image effect and use Shader to draw various gradient effects.
setShader(Shader shader)
Set the shadow layer under the image to produce the shadow effect.
setShadowLayer(float radius ,float dx,float dy,int color)
Set the paint brush Style
setStyle(Paint.Style style)
Set the paint Style
setStrokeCap(Paint.Cap cap)
Set the combination of various images during painting
setStrokeJoin(Paint.Join join)
Set the paint width.
setStrokeWidth(float width)
Set the processing method for overlapping Images
setXfermode(Xfermode xfermode)
Set and implement bold text
setFakeBoldText(boolean fakeBoldText)
True = helps display text on the LCD screen
setSubpixelText(boolean subpixelText)
Set the alignment direction of the drawn text
setTextAlign(Paint.Align align)
Set the zooming ratio of the X axis of the drawn text
setTextScaleX(float scaleX)
Set the font size of the drawn text
setTextSize(float textSize)
Set italic text. skewX is a skewed radian.
setTextSkewX(float skewX)
Set Typeface object
setTypeface(Typeface typeface)
Underline
setUnderlineText(boolean underlineText)
Set strikethrough
setStrikeThruText(boolean strikeThruText)