RecordingCanvas
class RecordingCanvas : Canvas
kotlin.Any | ||
↳ | android.graphics.Canvas | |
↳ | android.graphics.RecordingCanvas |
A Canvas implementation that records view system drawing operations for deferred rendering. This is used in combination with RenderNode. This class keeps a list of all the Paint and Bitmap objects that it draws, preventing the backing memory of Bitmaps from being released while the RecordingCanvas is still holding a native reference to the memory. This is obtained by calling RenderNode#beginRecording()
and is valid until the matching RenderNode#endRecording()
is called. It must not be retained beyond that as it is internally reused.
Summary
Inherited constants | |
---|---|
Public methods | |
---|---|
Unit |
disableZ() |
Unit | |
Unit |
drawArc(left: Float, top: Float, right: Float, bottom: Float, startAngle: Float, sweepAngle: Float, useCenter: Boolean, paint: Paint) Draw the specified arc, which will be scaled to fit inside the specified oval. |
Unit |
Draw the specified arc, which will be scaled to fit inside the specified oval. |
Unit |
drawBitmap(bitmap: Bitmap, left: Float, top: Float, paint: Paint?) Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix. |
Unit |
drawBitmap(bitmap: Bitmap, matrix: Matrix, paint: Paint?) Draw the bitmap using the specified matrix. |
Unit |
drawBitmap(bitmap: Bitmap, src: Rect?, dst: Rect, paint: Paint?) Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle. |
Unit |
drawBitmap(bitmap: Bitmap, src: Rect?, dst: RectF, paint: Paint?) Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle. |
Unit | |
Unit | |
Unit |
drawBitmapMesh(bitmap: Bitmap, meshWidth: Int, meshHeight: Int, verts: FloatArray, vertOffset: Int, colors: IntArray?, colorOffset: Int, paint: Paint?) Draw the bitmap through the mesh, where mesh vertices are evenly distributed across the bitmap. |
Unit |
drawCircle(cx: Float, cy: Float, radius: Float, paint: Paint) Draw the specified circle using the specified paint. |
Unit | |
Unit |
drawColor(color: Int, mode: PorterDuff.Mode) Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and porter-duff xfermode. |
Unit |
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and blendmode. |
Unit |
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and blendmode. |
Unit |
drawDoubleRoundRect(outer: RectF, outerRx: Float, outerRy: Float, inner: RectF, innerRx: Float, innerRy: Float, paint: Paint) Draws a double rounded rectangle using the specified paint. |
Unit |
drawDoubleRoundRect(outer: RectF, outerRadii: FloatArray, inner: RectF, innerRadii: FloatArray, paint: Paint) Draws a double rounded rectangle using the specified paint. |
Unit |
drawGlyphs(glyphIds: IntArray, glyphIdOffset: Int, positions: FloatArray, positionOffset: Int, glyphCount: Int, font: Font, paint: Paint) Draw array of glyphs with specified font. |
Unit |
Draw a line segment with the specified start and stop x,y coordinates, using the specified paint. |
Unit |
drawLines(pts: FloatArray, offset: Int, count: Int, paint: Paint) Draw a series of lines. |
Unit |
drawLines(pts: FloatArray, paint: Paint) |
Unit |
Draws a mesh object to the screen. |
Unit |
Draw the specified oval using the specified paint. |
Unit |
Draw the specified oval using the specified paint. |
Unit |
Fill the entire canvas' bitmap (restricted to the current clip) with the specified paint. |
Unit |
Draws the specified bitmap as an N-patch (most often, a 9-patch.) |
Unit |
Draws the specified bitmap as an N-patch (most often, a 9-patch.) |
Unit |
Draw the specified path using the specified paint. |
Unit |
drawPicture(picture: Picture) Save the canvas state, draw the picture, and restore the canvas state. |
Unit |
drawPicture(picture: Picture, dst: Rect) Draw the picture, stretched to fit into the dst rectangle. |
Unit |
drawPicture(picture: Picture, dst: RectF) Draw the picture, stretched to fit into the dst rectangle. |
Unit |
Helper for drawPoints() for drawing a single point. |
Unit |
drawPoints(pts: FloatArray!, offset: Int, count: Int, paint: Paint) Draw a series of points. |
Unit |
drawPoints(pts: FloatArray, paint: Paint) Helper for drawPoints() that assumes you want to draw the entire array |
Unit |
drawPosText(text: CharArray, index: Int, count: Int, pos: FloatArray, paint: Paint) |
Unit |
drawPosText(text: String, pos: FloatArray, paint: Paint) |
Unit | |
Unit |
Draw the specified Rect using the specified paint. |
Unit |
Draw the specified Rect using the specified Paint. |
Unit |
Draw the specified Rect using the specified paint. |
Unit |
drawRegion(region: Region, paint: Paint) |
Unit |
drawRenderNode(renderNode: RenderNode) Draws the specified display list onto this canvas. |
Unit |
drawRoundRect(left: Float, top: Float, right: Float, bottom: Float, rx: Float, ry: Float, paint: Paint) Draw the specified round-rect using the specified paint. |
Unit |
drawRoundRect(rect: RectF, rx: Float, ry: Float, paint: Paint) Draw the specified round-rect using the specified paint. |
Unit |
Draw the text, with origin at (x,y), using the specified paint. |
Unit |
Draw the specified range of text, specified by start/end, with its origin at (x,y), in the specified Paint. |
Unit |
Draw the text, with origin at (x,y), using the specified paint. |
Unit |
Draw the text, with origin at (x,y), using the specified paint. |
Unit |
drawTextOnPath(text: CharArray, index: Int, count: Int, path: Path, hOffset: Float, vOffset: Float, paint: Paint) Draw the text, with origin at (x,y), using the specified paint, along the specified path. |
Unit |
Draw the text, with origin at (x,y), using the specified paint, along the specified path. |
Unit |
drawTextRun(text: CharArray, index: Int, count: Int, contextIndex: Int, contextCount: Int, x: Float, y: Float, isRtl: Boolean, paint: Paint) Draw a run of text, all in a single direction, with optional context for complex text shaping. |
Unit |
drawTextRun(text: CharSequence, start: Int, end: Int, contextStart: Int, contextEnd: Int, x: Float, y: Float, isRtl: Boolean, paint: Paint) Draw a run of text, all in a single direction, with optional context for complex text shaping. |
Unit |
drawTextRun(measuredText: MeasuredText, start: Int, end: Int, contextStart: Int, contextEnd: Int, x: Float, y: Float, isRtl: Boolean, paint: Paint) Draw a run of text, all in a single direction, with optional context for complex text shaping. |
Unit |
drawVertices(mode: Canvas.VertexMode, vertexCount: Int, verts: FloatArray, vertOffset: Int, texs: FloatArray?, texOffset: Int, colors: IntArray?, colorOffset: Int, indices: ShortArray?, indexOffset: Int, indexCount: Int, paint: Paint) Draw the array of vertices, interpreted as triangles (based on mode). |
Unit |
enableZ() |
Int | |
Int | |
Int | |
Int |
getWidth() |
Boolean | |
Boolean |
isOpaque() |
Unit | |
Unit |
setDensity(density: Int) |
Inherited functions | |
---|---|
Public methods
drawARGB
fun drawARGB(
a: Int,
r: Int,
g: Int,
b: Int
): Unit
Parameters | |
---|---|
a |
Int: alpha component (0..255) of the color to draw onto the canvas |
r |
Int: red component (0..255) of the color to draw onto the canvas |
g |
Int: green component (0..255) of the color to draw onto the canvas |
b |
Int: blue component (0..255) of the color to draw onto the canvas |
drawArc
fun drawArc(
left: Float,
top: Float,
right: Float,
bottom: Float,
startAngle: Float,
sweepAngle: Float,
useCenter: Boolean,
paint: Paint
): Unit
Draw the specified arc, which will be scaled to fit inside the specified oval.
If the start angle is negative or >= 360, the start angle is treated as start angle modulo 360.
If the sweep angle is >= 360, then the oval is drawn completely. Note that this differs slightly from SkPath::arcTo, which treats the sweep angle modulo 360. If the sweep angle is negative, the sweep angle is treated as sweep angle modulo 360
The arc is drawn clockwise. An angle of 0 degrees correspond to the geometric angle of 0 degrees (3 o'clock on a watch.)
Parameters | |
---|---|
startAngle |
Float: Starting angle (in degrees) where the arc begins |
sweepAngle |
Float: Sweep angle (in degrees) measured clockwise |
useCenter |
Boolean: If true, include the center of the oval in the arc, and close it if it is being stroked. This will draw a wedge |
paint |
Paint: This value cannot be null . |
drawArc
fun drawArc(
oval: RectF,
startAngle: Float,
sweepAngle: Float,
useCenter: Boolean,
paint: Paint
): Unit
Draw the specified arc, which will be scaled to fit inside the specified oval.
If the start angle is negative or >= 360, the start angle is treated as start angle modulo 360.
If the sweep angle is >= 360, then the oval is drawn completely. Note that this differs slightly from SkPath::arcTo, which treats the sweep angle modulo 360. If the sweep angle is negative, the sweep angle is treated as sweep angle modulo 360
The arc is drawn clockwise. An angle of 0 degrees correspond to the geometric angle of 0 degrees (3 o'clock on a watch.)
Parameters | |
---|---|
oval |
RectF: This value cannot be null . |
startAngle |
Float: Starting angle (in degrees) where the arc begins |
sweepAngle |
Float: Sweep angle (in degrees) measured clockwise |
useCenter |
Boolean: If true, include the center of the oval in the arc, and close it if it is being stroked. This will draw a wedge |
paint |
Paint: This value cannot be null . |
drawBitmap
fun drawBitmap(
bitmap: Bitmap,
left: Float,
top: Float,
paint: Paint?
): Unit
Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix.
Note: if the paint contains a maskfilter that generates a mask which extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), then the bitmap will be drawn as if it were in a Shader with CLAMP mode. Thus the color outside of the original width/height will be the edge color replicated.
If the bitmap and canvas have different densities, this function will take care of automatically scaling the bitmap to draw at the same density as the canvas.
Parameters | |
---|---|
bitmap |
Bitmap: This value cannot be null . |
left |
Float: The position of the left side of the bitmap being drawn |
top |
Float: The position of the top side of the bitmap being drawn |
paint |
Paint?: This value may be null . |
drawBitmap
fun drawBitmap(
bitmap: Bitmap,
matrix: Matrix,
paint: Paint?
): Unit
Draw the bitmap using the specified matrix.
Parameters | |
---|---|
bitmap |
Bitmap: This value cannot be null . |
matrix |
Matrix: This value cannot be null . |
paint |
Paint?: This value may be null . |
drawBitmap
fun drawBitmap(
bitmap: Bitmap,
src: Rect?,
dst: Rect,
paint: Paint?
): Unit
Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle. If the source rectangle is not null, it specifies the subset of the bitmap to draw.
Note: if the paint contains a maskfilter that generates a mask which extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), then the bitmap will be drawn as if it were in a Shader with CLAMP mode. Thus the color outside of the original width/height will be the edge color replicated.
This function ignores the density associated with the bitmap. This is because the source and destination rectangle coordinate spaces are in their respective densities, so must already have the appropriate scaling factor applied.
Parameters | |
---|---|
bitmap |
Bitmap: This value cannot be null . |
src |
Rect?: This value may be null . |
dst |
Rect: This value cannot be null . |
paint |
Paint?: This value may be null . |
drawBitmap
fun drawBitmap(
bitmap: Bitmap,
src: Rect?,
dst: RectF,
paint: Paint?
): Unit
Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle. If the source rectangle is not null, it specifies the subset of the bitmap to draw.
Note: if the paint contains a maskfilter that generates a mask which extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), then the bitmap will be drawn as if it were in a Shader with CLAMP mode. Thus the color outside of the original width/height will be the edge color replicated.
This function ignores the density associated with the bitmap. This is because the source and destination rectangle coordinate spaces are in their respective densities, so must already have the appropriate scaling factor applied.
Parameters | |
---|---|
bitmap |
Bitmap: This value cannot be null . |
src |
Rect?: This value may be null . |
dst |
RectF: This value cannot be null . |
paint |
Paint?: This value may be null . |
drawBitmap
fundrawBitmap(
colors: IntArray,
offset: Int,
stride: Int,
x: Float,
y: Float,
width: Int,
height: Int,
hasAlpha: Boolean,
paint: Paint?
): Unit
Deprecated: checkstyle
Parameters | |
---|---|
colors |
IntArray: This value cannot be null . |
offset |
Int: Offset into the array of colors for the first pixel |
stride |
Int: The number of colors in the array between rows (must be >= width or <= -width). |
x |
Float: The X coordinate for where to draw the bitmap |
y |
Float: The Y coordinate for where to draw the bitmap |
width |
Int: The width of the bitmap |
height |
Int: The height of the bitmap |
hasAlpha |
Boolean: True if the alpha channel of the colors contains valid values. If false, the alpha byte is ignored (assumed to be 0xFF for every pixel). |
paint |
Paint?: This value may be null . |
drawBitmap
fundrawBitmap(
colors: IntArray,
offset: Int,
stride: Int,
x: Int,
y: Int,
width: Int,
height: Int,
hasAlpha: Boolean,
paint: Paint?
): Unit
Deprecated: checkstyle
Parameters | |
---|---|
colors |
IntArray: This value cannot be null . |
paint |
Paint?: This value may be null . |
drawBitmapMesh
fun drawBitmapMesh(
bitmap: Bitmap,
meshWidth: Int,
meshHeight: Int,
verts: FloatArray,
vertOffset: Int,
colors: IntArray?,
colorOffset: Int,
paint: Paint?
): Unit
Draw the bitmap through the mesh, where mesh vertices are evenly distributed across the bitmap. There are meshWidth+1 vertices across, and meshHeight+1 vertices down. The verts array is accessed in row-major order, so that the first meshWidth+1 vertices are distributed across the top of the bitmap from left to right. A more general version of this method is drawVertices(). Prior to API level {@value android.os.Build.VERSION_CODES#P Build.VERSION_CODES#P} vertOffset and colorOffset were ignored, effectively treating them as zeros. In API level {@value android.os.Build.VERSION_CODES#P Build.VERSION_CODES#P} and above these parameters will be respected.
Note: antialiasing is not supported, therefore Paint#ANTI_ALIAS_FLAG
is ignored.
Parameters | |
---|---|
bitmap |
Bitmap: This value cannot be null . |
meshWidth |
Int: The number of columns in the mesh. Nothing is drawn if this is 0 |
meshHeight |
Int: The number of rows in the mesh. Nothing is drawn if this is 0 |
verts |
FloatArray: This value cannot be null . |
vertOffset |
Int: Number of verts elements to skip before drawing |
colors |
IntArray?: This value may be null . |
colorOffset |
Int: Number of color elements to skip before drawing |
paint |
Paint?: This value may be null . |
drawCircle
fun drawCircle(
cx: Float,
cy: Float,
radius: Float,
paint: Paint
): Unit
Draw the specified circle using the specified paint. If radius is <= 0, then nothing will be drawn. The circle will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
cx |
Float: The x-coordinate of the center of the circle to be drawn |
cy |
Float: The y-coordinate of the center of the circle to be drawn |
radius |
Float: The radius of the circle to be drawn |
paint |
Paint: This value cannot be null . |
drawColor
fun drawColor(color: Int): Unit
Parameters | |
---|---|
color |
Int: the color to draw onto the canvas |
drawColor
fun drawColor(
color: Int,
mode: PorterDuff.Mode
): Unit
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and porter-duff xfermode.
Parameters | |
---|---|
color |
Int: the color to draw onto the canvas |
mode |
PorterDuff.Mode: This value cannot be null . |
drawColor
fun drawColor(
color: Int,
mode: BlendMode
): Unit
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and blendmode.
Parameters | |
---|---|
color |
Int: the color to draw onto the canvas |
mode |
BlendMode: This value cannot be null . |
drawColor
fun drawColor(
color: Long,
mode: BlendMode
): Unit
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and blendmode.
Parameters | |
---|---|
color |
Long: the ColorLong to draw onto the canvas. See the Color class for details about ColorLong s. |
mode |
BlendMode: This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the color space encoded in the ColorLong is invalid or unknown. |
drawDoubleRoundRect
fun drawDoubleRoundRect(
outer: RectF,
outerRx: Float,
outerRy: Float,
inner: RectF,
innerRx: Float,
innerRy: Float,
paint: Paint
): Unit
Draws a double rounded rectangle using the specified paint. The resultant round rect will be filled in the area defined between the outer and inner rectangular bounds if the Paint
configured with Paint.Style#FILL
. Otherwise if Paint.Style#STROKE
is used, then 2 rounded rect strokes will be drawn at the outer and inner rounded rectangles
Parameters | |
---|---|
outer |
RectF: This value cannot be null . |
outerRx |
Float: The x-radius of the oval used to round the corners on the outer rectangle |
outerRy |
Float: The y-radius of the oval used to round the corners on the outer rectangle |
inner |
RectF: This value cannot be null . |
innerRx |
Float: The x-radius of the oval used to round the corners on the inner rectangle |
innerRy |
Float: The y-radius of the oval used to round the corners on the outer rectangle |
paint |
Paint: This value cannot be null . |
drawDoubleRoundRect
fun drawDoubleRoundRect(
outer: RectF,
outerRadii: FloatArray,
inner: RectF,
innerRadii: FloatArray,
paint: Paint
): Unit
Draws a double rounded rectangle using the specified paint. The resultant round rect will be filled in the area defined between the outer and inner rectangular bounds if the Paint
configured with Paint.Style#FILL
. Otherwise if Paint.Style#STROKE
is used, then 2 rounded rect strokes will be drawn at the outer and inner rounded rectangles
Parameters | |
---|---|
outer |
RectF: This value cannot be null . |
outerRadii |
FloatArray: This value cannot be null . |
inner |
RectF: This value cannot be null . |
innerRadii |
FloatArray: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawGlyphs
fun drawGlyphs(
glyphIds: IntArray,
glyphIdOffset: Int,
positions: FloatArray,
positionOffset: Int,
glyphCount: Int,
font: Font,
paint: Paint
): Unit
Draw array of glyphs with specified font.
Parameters | |
---|---|
glyphIds |
IntArray: This value cannot be null . |
glyphIdOffset |
Int: Value is 0 or greater |
positions |
FloatArray: This value cannot be null . |
positionOffset |
Int: Value is 0 or greater |
glyphCount |
Int: Value is 0 or greater |
font |
Font: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawLine
fun drawLine(
startX: Float,
startY: Float,
stopX: Float,
stopY: Float,
paint: Paint
): Unit
Draw a line segment with the specified start and stop x,y coordinates, using the specified paint.
Note that since a line is always "framed", the Style is ignored in the paint.
Degenerate lines (length is 0) will not be drawn.
Parameters | |
---|---|
startX |
Float: The x-coordinate of the start point of the line |
startY |
Float: The y-coordinate of the start point of the line |
paint |
Paint: This value cannot be null . |
drawLines
fun drawLines(
pts: FloatArray,
offset: Int,
count: Int,
paint: Paint
): Unit
Draw a series of lines. Each line is taken from 4 consecutive values in the pts array. Thus to draw 1 line, the array must contain at least 4 values. This is logically the same as drawing the array as follows: drawLine(pts[0], pts[1], pts[2], pts[3]) followed by drawLine(pts[4], pts[5], pts[6], pts[7]) and so on.
Parameters | |
---|---|
pts |
FloatArray: This value cannot be null . |
offset |
Int: Number of values in the array to skip before drawing. |
count |
Int: The number of values in the array to process, after skipping "offset" of them. Since each line uses 4 values, the number of "lines" that are drawn is really (count >> 2). |
paint |
Paint: This value cannot be null . |
drawLines
fun drawLines(
pts: FloatArray,
paint: Paint
): Unit
Parameters | |
---|---|
pts |
FloatArray: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawMesh
fun drawMesh(
mesh: Mesh,
blendMode: BlendMode?,
paint: Paint
): Unit
Draws a mesh object to the screen.
Note: antialiasing is not supported, therefore Paint#ANTI_ALIAS_FLAG
is ignored.
Parameters | |
---|---|
mesh |
Mesh: This value cannot be null . |
blendMode |
BlendMode?: This value may be null . |
paint |
Paint: This value cannot be null . |
drawOval
fun drawOval(
left: Float,
top: Float,
right: Float,
bottom: Float,
paint: Paint
): Unit
Draw the specified oval using the specified paint. The oval will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
paint |
Paint: This value cannot be null . |
drawOval
fun drawOval(
oval: RectF,
paint: Paint
): Unit
Draw the specified oval using the specified paint. The oval will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
oval |
RectF: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawPaint
fun drawPaint(paint: Paint): Unit
Fill the entire canvas' bitmap (restricted to the current clip) with the specified paint. This is equivalent (but faster) to drawing an infinitely large rectangle with the specified paint.
Parameters | |
---|---|
paint |
Paint: This value cannot be null . |
drawPatch
fun drawPatch(
patch: NinePatch,
dst: Rect,
paint: Paint?
): Unit
Draws the specified bitmap as an N-patch (most often, a 9-patch.)
Note: antialiasing is not supported, therefore Paint#ANTI_ALIAS_FLAG
is ignored.
Parameters | |
---|---|
patch |
NinePatch: This value cannot be null . |
dst |
Rect: This value cannot be null . |
paint |
Paint?: This value may be null . |
drawPatch
fun drawPatch(
patch: NinePatch,
dst: RectF,
paint: Paint?
): Unit
Draws the specified bitmap as an N-patch (most often, a 9-patch.)
Note: antialiasing is not supported, therefore Paint#ANTI_ALIAS_FLAG
is ignored.
Parameters | |
---|---|
patch |
NinePatch: This value cannot be null . |
dst |
RectF: This value cannot be null . |
paint |
Paint?: This value may be null . |
drawPath
fun drawPath(
path: Path,
paint: Paint
): Unit
Draw the specified path using the specified paint. The path will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
path |
Path: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawPicture
fun drawPicture(picture: Picture): Unit
Save the canvas state, draw the picture, and restore the canvas state. This differs from picture.draw(canvas), which does not perform any save/restore.
Note: This forces the picture to internally call Picture#endRecording
in order to prepare for playback.
Parameters | |
---|---|
picture |
Picture: This value cannot be null . |
drawPicture
fun drawPicture(
picture: Picture,
dst: Rect
): Unit
Draw the picture, stretched to fit into the dst rectangle.
Parameters | |
---|---|
picture |
Picture: This value cannot be null . |
dst |
Rect: This value cannot be null . |
drawPicture
fun drawPicture(
picture: Picture,
dst: RectF
): Unit
Draw the picture, stretched to fit into the dst rectangle.
Parameters | |
---|---|
picture |
Picture: This value cannot be null . |
dst |
RectF: This value cannot be null . |
drawPoint
fun drawPoint(
x: Float,
y: Float,
paint: Paint
): Unit
Helper for drawPoints() for drawing a single point.
Parameters | |
---|---|
paint |
Paint: This value cannot be null . |
drawPoints
fun drawPoints(
pts: FloatArray!,
offset: Int,
count: Int,
paint: Paint
): Unit
Draw a series of points. Each point is centered at the coordinate specified by pts[], and its diameter is specified by the paint's stroke width (as transformed by the canvas' CTM), with special treatment for a stroke width of 0, which always draws exactly 1 pixel (or at most 4 if antialiasing is enabled). The shape of the point is controlled by the paint's Cap type. The shape is a square, unless the cap type is Round, in which case the shape is a circle.
Parameters | |
---|---|
pts |
FloatArray!: Array of points to draw [x0 y0 x1 y1 x2 y2 ...] |
offset |
Int: Number of values to skip before starting to draw. |
count |
Int: The number of values to process, after skipping offset of them. Since one point uses two values, the number of "points" that are drawn is really (count >> 1). |
paint |
Paint: This value cannot be null . |
drawPoints
fun drawPoints(
pts: FloatArray,
paint: Paint
): Unit
Helper for drawPoints() that assumes you want to draw the entire array
Parameters | |
---|---|
pts |
FloatArray: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawPosText
fundrawPosText(
text: CharArray,
index: Int,
count: Int,
pos: FloatArray,
paint: Paint
): Unit
Deprecated: checkstyle
Parameters | |
---|---|
text |
CharArray: This value cannot be null . |
index |
Int: The index of the first character to draw |
count |
Int: The number of characters to draw, starting from index. |
pos |
FloatArray: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawPosText
fundrawPosText(
text: String,
pos: FloatArray,
paint: Paint
): Unit
Deprecated: checkstyle
Parameters | |
---|---|
text |
String: This value cannot be null . |
pos |
FloatArray: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawRGB
fun drawRGB(
r: Int,
g: Int,
b: Int
): Unit
Parameters | |
---|---|
r |
Int: red component (0..255) of the color to draw onto the canvas |
g |
Int: green component (0..255) of the color to draw onto the canvas |
b |
Int: blue component (0..255) of the color to draw onto the canvas |
drawRect
fun drawRect(
left: Float,
top: Float,
right: Float,
bottom: Float,
paint: Paint
): Unit
Draw the specified Rect using the specified paint. The rectangle will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
left |
Float: The left side of the rectangle to be drawn |
top |
Float: The top side of the rectangle to be drawn |
right |
Float: The right side of the rectangle to be drawn |
bottom |
Float: The bottom side of the rectangle to be drawn |
paint |
Paint: This value cannot be null . |
drawRect
fun drawRect(
r: Rect,
paint: Paint
): Unit
Draw the specified Rect using the specified Paint. The rectangle will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
r |
Rect: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawRect
fun drawRect(
rect: RectF,
paint: Paint
): Unit
Draw the specified Rect using the specified paint. The rectangle will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
rect |
RectF: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawRegion
fun drawRegion(
region: Region,
paint: Paint
): Unit
Parameters | |
---|---|
region |
Region: This value cannot be null . |
paint |
Paint: This value cannot be null . |
drawRenderNode
fun drawRenderNode(renderNode: RenderNode): Unit
Draws the specified display list onto this canvas.
Parameters | |
---|---|
renderNode |
RenderNode: The RenderNode to draw. This value cannot be null . |
drawRoundRect
fun drawRoundRect(
left: Float,
top: Float,
right: Float,
bottom: Float,
rx: Float,
ry: Float,
paint: Paint
): Unit
Draw the specified round-rect using the specified paint. The roundrect will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
rx |
Float: The x-radius of the oval used to round the corners |
ry |
Float: The y-radius of the oval used to round the corners |
paint |
Paint: This value cannot be null . |
drawRoundRect
fun drawRoundRect(
rect: RectF,
rx: Float,
ry: Float,
paint: Paint
): Unit
Draw the specified round-rect using the specified paint. The roundrect will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
rect |
RectF: This value cannot be null . |
rx |
Float: The x-radius of the oval used to round the corners |
ry |
Float: The y-radius of the oval used to round the corners |
paint |
Paint: This value cannot be null . |
drawText
fun drawText(
text: CharArray,
index: Int,
count: Int,
x: Float,
y: Float,
paint: Paint
): Unit
Draw the text, with origin at (x,y), using the specified paint. The origin is interpreted based on the Align setting in the paint.
Parameters | |
---|---|
text |
CharArray: This value cannot be null . |
x |
Float: The x-coordinate of the origin of the text being drawn |
y |
Float: The y-coordinate of the baseline of the text being drawn |
paint |
Paint: This value cannot be null . |
drawText
fun drawText(
text: CharSequence,
start: Int,
end: Int,
x: Float,
y: Float,
paint: Paint
): Unit
Draw the specified range of text, specified by start/end, with its origin at (x,y), in the specified Paint. The origin is interpreted based on the Align setting in the Paint.
Parameters | |
---|---|
text |
CharSequence: This value cannot be null . |
start |
Int: The index of the first character in text to draw |
end |
Int: (end - 1) is the index of the last character in text to draw |
x |
Float: The x-coordinate of origin for where to draw the text |
y |
Float: The y-coordinate of origin for where to draw the text |
paint |
Paint: This value cannot be null . |
drawText
fun drawText(
text: String,
x: Float,
y: Float,
paint: Paint
): Unit
Draw the text, with origin at (x,y), using the specified paint. The origin is interpreted based on the Align setting in the paint.
Parameters | |
---|---|
text |
String: This value cannot be null . |
x |
Float: The x-coordinate of the origin of the text being drawn |
y |
Float: The y-coordinate of the baseline of the text being drawn |
paint |
Paint: This value cannot be null . |
drawText
fun drawText(
text: String,
start: Int,
end: Int,
x: Float,
y: Float,
paint: Paint
): Unit
Draw the text, with origin at (x,y), using the specified paint. The origin is interpreted based on the Align setting in the paint.
Parameters | |
---|---|
text |
String: This value cannot be null . |
start |
Int: The index of the first character in text to draw |
end |
Int: (end - 1) is the index of the last character in text to draw |
x |
Float: The x-coordinate of the origin of the text being drawn |
y |
Float: The y-coordinate of the baseline of the text being drawn |
paint |
Paint: This value cannot be null . |
drawTextOnPath
fun drawTextOnPath(
text: CharArray,
index: Int,
count: Int,
path: Path,
hOffset: Float,
vOffset: Float,
paint: Paint
): Unit
Draw the text, with origin at (x,y), using the specified paint, along the specified path. The paint's Align setting determines where along the path to start the text.
Parameters | |
---|---|
text |
CharArray: This value cannot be null . |
index |
Int: The starting index within the text to be drawn |
count |
Int: Starting from index, the number of characters to draw |
path |
Path: This value cannot be null . |
hOffset |
Float: The distance along the path to add to the text's starting position |
vOffset |
Float: The distance above(-) or below(+) the path to position the text |
paint |
Paint: This value cannot be null . |
drawTextOnPath
fun drawTextOnPath(
text: String,
path: Path,
hOffset: Float,
vOffset: Float,
paint: Paint
): Unit
Draw the text, with origin at (x,y), using the specified paint, along the specified path. The paint's Align setting determines where along the path to start the text.
Parameters | |
---|---|
text |
String: This value cannot be null . |
path |
Path: This value cannot be null . |
hOffset |
Float: The distance along the path to add to the text's starting position |
vOffset |
Float: The distance above(-) or below(+) the path to position the text |
paint |
Paint: This value cannot be null . |
drawTextRun
fun drawTextRun(
text: CharArray,
index: Int,
count: Int,
contextIndex: Int,
contextCount: Int,
x: Float,
y: Float,
isRtl: Boolean,
paint: Paint
): Unit
Draw a run of text, all in a single direction, with optional context for complex text shaping.
See drawTextRun(java.lang.CharSequence,int,int,int,int,float,float,boolean,android.graphics.Paint)
for more details. This method uses a character array rather than CharSequence to represent the string. Also, to be consistent with the pattern established in #drawText, in this method count
and contextCount
are used rather than offsets of the end position; count = end - start, contextCount = contextEnd - contextStart
.
Parameters | |
---|---|
text |
CharArray: This value cannot be null . |
index |
Int: the start of the text to render |
count |
Int: the count of chars to render |
contextIndex |
Int: the start of the context for shaping. Must be no greater than index. |
contextCount |
Int: the number of characters in the context for shaping. contexIndex + contextCount must be no less than index + count. |
x |
Float: the x position at which to draw the text |
y |
Float: the y position at which to draw the text |
isRtl |
Boolean: whether the run is in RTL direction |
paint |
Paint: This value cannot be null . |
drawTextRun
fun drawTextRun(
text: CharSequence,
start: Int,
end: Int,
contextStart: Int,
contextEnd: Int,
x: Float,
y: Float,
isRtl: Boolean,
paint: Paint
): Unit
Draw a run of text, all in a single direction, with optional context for complex text shaping.
The run of text includes the characters from start
to end
in the text. In addition, the range contextStart
to contextEnd
is used as context for the purpose of complex text shaping, such as Arabic text potentially shaped differently based on the text next to it.
All text outside the range contextStart..contextEnd
is ignored. The text between start
and end
will be laid out and drawn. The context range is useful for contextual shaping, e.g. Kerning, Arabic contextural form.
The direction of the run is explicitly specified by isRtl
. Thus, this method is suitable only for runs of a single direction. Alignment of the text is as determined by the Paint's TextAlign value. Further, 0 <= contextStart <= start <= end <= contextEnd <= text.length
must hold on entry.
Also see android.graphics.Paint#getRunAdvance for a corresponding method to measure the text; the advance width of the text drawn matches the value obtained from that method.
Parameters | |
---|---|
text |
CharSequence: This value cannot be null . |
start |
Int: the start of the text to render. Data before this position can be used for shaping context. |
end |
Int: the end of the text to render. Data at or after this position can be used for shaping context. |
contextStart |
Int: the index of the start of the shaping context |
contextEnd |
Int: the index of the end of the shaping context |
x |
Float: the x position at which to draw the text |
y |
Float: the y position at which to draw the text |
isRtl |
Boolean: whether the run is in RTL direction |
paint |
Paint: This value cannot be null . |
drawTextRun
fun drawTextRun(
measuredText: MeasuredText,
start: Int,
end: Int,
contextStart: Int,
contextEnd: Int,
x: Float,
y: Float,
isRtl: Boolean,
paint: Paint
): Unit
Draw a run of text, all in a single direction, with optional context for complex text shaping.
See drawTextRun(java.lang.CharSequence,int,int,int,int,float,float,boolean,android.graphics.Paint)
for more details. This method uses a MeasuredText
rather than CharSequence to represent the string.
Parameters | |
---|---|
text |
the text to render This value cannot be null . |
start |
Int: the start of the text to render. Data before this position can be used for shaping context. |
end |
Int: the end of the text to render. Data at or after this position can be used for shaping context. |
contextStart |
Int: the index of the start of the shaping context |
contextEnd |
Int: the index of the end of the shaping context |
x |
Float: the x position at which to draw the text |
y |
Float: the y position at which to draw the text |
isRtl |
Boolean: whether the run is in RTL direction |
paint |
Paint: This value cannot be null . |
measuredText |
MeasuredText: This value cannot be null . |
drawVertices
fun drawVertices(
mode: Canvas.VertexMode,
vertexCount: Int,
verts: FloatArray,
vertOffset: Int,
texs: FloatArray?,
texOffset: Int,
colors: IntArray?,
colorOffset: Int,
indices: ShortArray?,
indexOffset: Int,
indexCount: Int,
paint: Paint
): Unit
Draw the array of vertices, interpreted as triangles (based on mode). The verts array is required, and specifies the x,y pairs for each vertex. If texs is non-null, then it is used to specify the coordinate in shader coordinates to use at each vertex (the paint must have a shader in this case). If there is no texs array, but there is a color array, then each color is interpolated across its corresponding triangle in a gradient. If both texs and colors arrays are present, then they behave as before, but the resulting color at each pixels is the result of multiplying the colors from the shader and the color-gradient together. The indices array is optional, but if it is present, then it is used to specify the index of each triangle, rather than just walking through the arrays in order.
Note: antialiasing is not supported, therefore Paint#ANTI_ALIAS_FLAG
is ignored.
Parameters | |
---|---|
mode |
Canvas.VertexMode: This value cannot be null . |
vertexCount |
Int: The number of values in the vertices array (and corresponding texs and colors arrays if non-null). Each logical vertex is two values (x, y), vertexCount must be a multiple of 2. |
verts |
FloatArray: This value cannot be null . |
vertOffset |
Int: Number of values in the verts to skip before drawing. |
texs |
FloatArray?: This value may be null . |
texOffset |
Int: Number of values in texs to skip before drawing. |
colors |
IntArray?: This value may be null . |
colorOffset |
Int: Number of values in colors to skip before drawing. |
indices |
ShortArray?: This value may be null . |
indexCount |
Int: Number of entries in the indices array (if not null). |
paint |
Paint: This value cannot be null . |
getHeight
fun getHeight(): Int
Return | |
---|---|
Int |
the height of the current drawing layer |
getWidth
fun getWidth(): Int
Return | |
---|---|
Int |
the width of the current drawing layer |
isHardwareAccelerated
fun isHardwareAccelerated(): Boolean
Return | |
---|---|
Boolean |
True if drawing operations are hardware accelerated, false otherwise. |
isOpaque
fun isOpaque(): Boolean
Return | |
---|---|
Boolean |
true if the device that the current layer draws into is opaque |
setBitmap
fun setBitmap(bitmap: Bitmap?): Unit
Parameters | |
---|---|
bitmap |
Bitmap?: Specifies a mutable bitmap for the canvas to draw into. This value may be null . |
setDensity
fun setDensity(density: Int): Unit
Parameters | |
---|---|
density |
Int: The new target density of the canvas, which is used to determine the scaling factor when drawing a bitmap into it. Use Bitmap#DENSITY_NONE to disable bitmap scaling. |