RecordingCanvas
public
final
class
RecordingCanvas
extends Canvas
java.lang.Object | ||
↳ | 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 | |
---|---|
void
|
disableZ()
Disables Z support, preventing any RenderNodes drawn after this point from being visually reordered or having shadows rendered. |
void
|
drawARGB(int a, int r, int g, int b)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified ARGB color, using srcover porterduff mode. |
void
|
drawArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
Draw the specified arc, which will be scaled to fit inside the specified oval. |
void
|
drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
Draw the specified arc, which will be scaled to fit inside the specified oval. |
void
|
drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint)
Draw the bitmap using the specified matrix. |
void
|
drawBitmap(int[] colors, int offset, int stride, float x, float y, int width, int height, boolean hasAlpha, Paint paint)
This method is deprecated. checkstyle |
void
|
drawBitmap(int[] colors, int offset, int stride, int x, int y, int width, int height, boolean hasAlpha, Paint paint)
This method is deprecated. checkstyle |
void
|
drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle. |
void
|
drawBitmap(Bitmap bitmap, float left, float top, Paint paint)
Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix. |
void
|
drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)
Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle. |
void
|
drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, int vertOffset, int[] colors, int colorOffset, Paint paint)
Draw the bitmap through the mesh, where mesh vertices are evenly distributed across the bitmap. |
void
|
drawCircle(float cx, float cy, float radius, Paint paint)
Draw the specified circle using the specified paint. |
void
|
drawColor(long color, BlendMode mode)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and blendmode. |
void
|
drawColor(int color)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color, using srcover porterduff mode. |
void
|
drawColor(int color, BlendMode mode)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and blendmode. |
void
|
drawColor(int color, PorterDuff.Mode mode)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and porter-duff xfermode. |
void
|
drawDoubleRoundRect(RectF outer, float[] outerRadii, RectF inner, float[] innerRadii, Paint paint)
Draws a double rounded rectangle using the specified paint. |
void
|
drawDoubleRoundRect(RectF outer, float outerRx, float outerRy, RectF inner, float innerRx, float innerRy, Paint paint)
Draws a double rounded rectangle using the specified paint. |
void
|
drawGlyphs(int[] glyphIds, int glyphIdOffset, float[] positions, int positionOffset, int glyphCount, Font font, Paint paint)
Draw array of glyphs with specified font. |
void
|
drawLine(float startX, float startY, float stopX, float stopY, Paint paint)
Draw a line segment with the specified start and stop x,y coordinates, using the specified paint. |
void
|
drawLines(float[] pts, int offset, int count, Paint paint)
Draw a series of lines. |
void
|
drawLines(float[] pts, Paint paint)
|
void
|
drawMesh(Mesh mesh, BlendMode blendMode, Paint paint)
Draws a mesh object to the screen. |
void
|
drawOval(float left, float top, float right, float bottom, Paint paint)
Draw the specified oval using the specified paint. |
void
|
drawOval(RectF oval, Paint paint)
Draw the specified oval using the specified paint. |
void
|
drawPaint(Paint paint)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified paint. |
void
|
drawPatch(NinePatch patch, RectF dst, Paint paint)
Draws the specified bitmap as an N-patch (most often, a 9-patch.) Note: antialiasing is not supported, therefore |
void
|
drawPatch(NinePatch patch, Rect dst, Paint paint)
Draws the specified bitmap as an N-patch (most often, a 9-patch.) Note: antialiasing is not supported, therefore |
void
|
drawPath(Path path, Paint paint)
Draw the specified path using the specified paint. |
void
|
drawPicture(Picture picture, Rect dst)
Draw the picture, stretched to fit into the dst rectangle. |
void
|
drawPicture(Picture picture, RectF dst)
Draw the picture, stretched to fit into the dst rectangle. |
void
|
drawPicture(Picture picture)
Save the canvas state, draw the picture, and restore the canvas state. |
void
|
drawPoint(float x, float y, Paint paint)
Helper for drawPoints() for drawing a single point. |
void
|
drawPoints(float[] pts, int offset, int count, Paint paint)
Draw a series of points. |
void
|
drawPoints(float[] pts, Paint paint)
Helper for drawPoints() that assumes you want to draw the entire array |
void
|
drawPosText(String text, float[] pos, Paint paint)
This method is deprecated. checkstyle |
void
|
drawPosText(char[] text, int index, int count, float[] pos, Paint paint)
This method is deprecated. checkstyle |
void
|
drawRGB(int r, int g, int b)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified RGB color, using srcover porterduff mode. |
void
|
drawRect(float left, float top, float right, float bottom, Paint paint)
Draw the specified Rect using the specified paint. |
void
|
drawRect(Rect r, Paint paint)
Draw the specified Rect using the specified Paint. |
void
|
drawRect(RectF rect, Paint paint)
Draw the specified Rect using the specified paint. |
void
|
drawRegion(Region region, Paint paint)
Draws the given region using the given paint. |
void
|
drawRenderNode(RenderNode renderNode)
Draws the specified display list onto this canvas. |
void
|
drawRoundRect(RectF rect, float rx, float ry, Paint paint)
Draw the specified round-rect using the specified paint. |
void
|
drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint)
Draw the specified round-rect using the specified paint. |
void
|
drawText(CharSequence text, int start, int end, float x, float y, Paint paint)
Draw the specified range of text, specified by start/end, with its origin at (x,y), in the specified Paint. |
void
|
drawText(String text, float x, float y, Paint paint)
Draw the text, with origin at (x,y), using the specified paint. |
void
|
drawText(String text, int start, int end, float x, float y, Paint paint)
Draw the text, with origin at (x,y), using the specified paint. |
void
|
drawText(char[] text, int index, int count, float x, float y, Paint paint)
Draw the text, with origin at (x,y), using the specified paint. |
void
|
drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint)
Draw the text, with origin at (x,y), using the specified paint, along the specified path. |
void
|
drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, float vOffset, Paint paint)
Draw the text, with origin at (x,y), using the specified paint, along the specified path. |
void
|
drawTextRun(MeasuredText measuredText, int start, int end, int contextStart, int contextEnd, float x, float y, boolean isRtl, Paint paint)
Draw a run of text, all in a single direction, with optional context for complex text shaping. |
void
|
drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, float x, float y, boolean isRtl, Paint paint)
Draw a run of text, all in a single direction, with optional context for complex text shaping. |
void
|
drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, float x, float y, boolean isRtl, Paint paint)
Draw a run of text, all in a single direction, with optional context for complex text shaping. |
void
|
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)
Draw the array of vertices, interpreted as triangles (based on mode). |
void
|
enableZ()
Enables Z support which defaults to disabled. |
int
|
getHeight()
Returns the height of the current drawing layer |
int
|
getMaximumBitmapHeight()
Returns the maximum allowed height for bitmaps drawn with this canvas. |
int
|
getMaximumBitmapWidth()
Returns the maximum allowed width for bitmaps drawn with this canvas. |
int
|
getWidth()
Returns the width of the current drawing layer |
boolean
|
isHardwareAccelerated()
Indicates whether this Canvas uses hardware acceleration. |
boolean
|
isOpaque()
Return true if the device that the current layer draws into is opaque (that is, it does not support per-pixel alpha). |
void
|
setBitmap(Bitmap bitmap)
Specify a bitmap for the canvas to draw into. |
void
|
setDensity(int density)
Specifies the density for this Canvas' backing bitmap. |
Inherited methods | |
---|---|
Public methods
disableZ
public void disableZ ()
Disables Z support, preventing any RenderNodes drawn after this point from being
visually reordered or having shadows rendered.
Note: This is not impacted by any save()
or restore()
calls as it is not
considered to be part of the current matrix or clip.
See enableZ()
drawARGB
public void drawARGB (int a, int r, int g, int b)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified ARGB color, using srcover porterduff mode.
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
public void drawArc (float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
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 | |
---|---|
left |
float |
top |
float |
right |
float |
bottom |
float |
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
public void drawArc (RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
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
public void drawBitmap (Bitmap bitmap, Matrix matrix, Paint paint)
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
public void drawBitmap (int[] colors, int offset, int stride, float x, float y, int width, int height, boolean hasAlpha, Paint paint)
This method is deprecated.
checkstyle
Treat the specified array of colors as a bitmap, and draw it. This gives the same result as first creating a bitmap from the array, and then drawing it, but this method avoids explicitly creating a bitmap object which can be more efficient if the colors are changing often.
Parameters | |
---|---|
colors |
int : 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
public void drawBitmap (int[] colors, int offset, int stride, int x, int y, int width, int height, boolean hasAlpha, Paint paint)
This method is deprecated.
checkstyle
Legacy version of drawBitmap(int[] colors, ...) that took ints for x,y
Parameters | |
---|---|
colors |
int : This value cannot be null . |
offset |
int |
stride |
int |
x |
int |
y |
int |
width |
int |
height |
int |
hasAlpha |
boolean |
paint |
Paint : This value may be null . |
drawBitmap
public void drawBitmap (Bitmap bitmap, Rect src, Rect dst, Paint paint)
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
public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)
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
public void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint)
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 . |
drawBitmapMesh
public void drawBitmapMesh (Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, int vertOffset, int[] colors, int colorOffset, Paint paint)
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 android.os.Build.VERSION_CODES.P Build.VERSION_CODES.P
vertOffset and colorOffset were ignored,
effectively treating them as zeros. In API level 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 |
float : This value cannot be null . |
vertOffset |
int : Number of verts elements to skip before drawing |
colors |
int : This value may be null . |
colorOffset |
int : Number of color elements to skip before drawing |
paint |
Paint : This value may be null . |
drawCircle
public void drawCircle (float cx, float cy, float radius, Paint paint)
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
public void drawColor (long color, BlendMode mode)
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 . |
drawColor
public void drawColor (int color)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color, using srcover porterduff mode.
Parameters | |
---|---|
color |
int : the color to draw onto the canvas |
drawColor
public void drawColor (int color, BlendMode mode)
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
public void drawColor (int color, PorterDuff.Mode mode)
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 . |
drawDoubleRoundRect
public void drawDoubleRoundRect (RectF outer, float[] outerRadii, RectF inner, float[] innerRadii, Paint paint)
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 |
float : This value cannot be null . |
inner |
RectF : This value cannot be null . |
innerRadii |
float : This value cannot be null . |
paint |
Paint : This value cannot be null . |
drawDoubleRoundRect
public void drawDoubleRoundRect (RectF outer, float outerRx, float outerRy, RectF inner, float innerRx, float innerRy, Paint paint)
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 . |
drawGlyphs
public void drawGlyphs (int[] glyphIds, int glyphIdOffset, float[] positions, int positionOffset, int glyphCount, Font font, Paint paint)
Draw array of glyphs with specified font.
Parameters | |
---|---|
glyphIds |
int : This value cannot be null . |
glyphIdOffset |
int : Value is 0 or greater |
positions |
float : 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
public void drawLine (float startX, float startY, float stopX, float stopY, Paint paint)
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 |
stopX |
float |
stopY |
float |
paint |
Paint : This value cannot be null . |
drawLines
public void drawLines (float[] pts, int offset, int count, Paint paint)
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 |
float : 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
public void drawLines (float[] pts, Paint paint)
Parameters | |
---|---|
pts |
float : This value cannot be null . |
paint |
Paint : This value cannot be null . |
drawMesh
public void drawMesh (Mesh mesh, BlendMode blendMode, Paint paint)
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
public void drawOval (float left, float top, float right, float bottom, Paint paint)
Draw the specified oval using the specified paint. The oval will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
left |
float |
top |
float |
right |
float |
bottom |
float |
paint |
Paint : This value cannot be null . |
drawOval
public void drawOval (RectF oval, Paint paint)
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
public void drawPaint (Paint paint)
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
public void drawPatch (NinePatch patch, RectF dst, Paint paint)
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 . |
drawPatch
public void drawPatch (NinePatch patch, Rect dst, Paint paint)
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 . |
drawPath
public void drawPath (Path path, Paint paint)
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
public void drawPicture (Picture picture, Rect dst)
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
public void drawPicture (Picture picture, RectF dst)
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 . |
drawPicture
public void drawPicture (Picture picture)
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 . |
drawPoint
public void drawPoint (float x, float y, Paint paint)
Helper for drawPoints() for drawing a single point.
Parameters | |
---|---|
x |
float |
y |
float |
paint |
Paint : This value cannot be null . |
drawPoints
public void drawPoints (float[] pts, int offset, int count, Paint paint)
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 |
float : 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
public void drawPoints (float[] pts, Paint paint)
Helper for drawPoints() that assumes you want to draw the entire array
Parameters | |
---|---|
pts |
float : This value cannot be null . |
paint |
Paint : This value cannot be null . |
drawPosText
public void drawPosText (String text, float[] pos, Paint paint)
This method is deprecated.
checkstyle
Draw the text in the array, with each character's origin specified by the pos array.
Parameters | |
---|---|
text |
String : This value cannot be null . |
pos |
float : This value cannot be null . |
paint |
Paint : This value cannot be null . |
drawPosText
public void drawPosText (char[] text, int index, int count, float[] pos, Paint paint)
This method is deprecated.
checkstyle
Draw the text in the array, with each character's origin specified by the pos array.
Parameters | |
---|---|
text |
char : 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 |
float : This value cannot be null . |
paint |
Paint : This value cannot be null . |
drawRGB
public void drawRGB (int r, int g, int b)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified RGB color, using srcover porterduff mode.
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
public void drawRect (float left, float top, float right, float bottom, Paint paint)
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
public void drawRect (Rect r, Paint paint)
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
public void drawRect (RectF rect, Paint paint)
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
public void drawRegion (Region region, Paint paint)
Draws the given region using the given paint.
Parameters | |
---|---|
region |
Region : This value cannot be null . |
paint |
Paint : This value cannot be null . |
drawRenderNode
public void drawRenderNode (RenderNode renderNode)
Draws the specified display list onto this canvas.
Parameters | |
---|---|
renderNode |
RenderNode : The RenderNode to draw.
This value cannot be null . |
drawRoundRect
public void drawRoundRect (RectF rect, float rx, float ry, Paint paint)
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 . |
drawRoundRect
public void drawRoundRect (float left, float top, float right, float bottom, float rx, float ry, Paint paint)
Draw the specified round-rect using the specified paint. The roundrect will be filled or framed based on the Style in the paint.
Parameters | |
---|---|
left |
float |
top |
float |
right |
float |
bottom |
float |
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
public void drawText (CharSequence text, int start, int end, float x, float y, Paint paint)
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
public void drawText (String text, float x, float y, Paint paint)
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
public void drawText (String text, int start, int end, float x, float y, Paint paint)
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 . |
drawText
public void drawText (char[] text, int index, int count, float x, float y, Paint paint)
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 |
char : This value cannot be null . |
index |
int |
count |
int |
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
public void drawTextOnPath (String text, Path path, float hOffset, float vOffset, Paint paint)
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 . |
drawTextOnPath
public void drawTextOnPath (char[] text, int index, int count, Path path, float hOffset, float vOffset, Paint paint)
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 |
char : 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 . |
drawTextRun
public void drawTextRun (MeasuredText measuredText, int start, int end, int contextStart, int contextEnd, float x, float y, boolean isRtl, Paint paint)
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 | |
---|---|
measuredText |
MeasuredText : 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
public void drawTextRun (char[] text, int index, int count, int contextIndex, int contextCount, float x, float y, boolean isRtl, Paint paint)
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(char, int, int, float, float, Paint)
, in this
method count
and contextCount
are used rather than offsets of the end
position; count = end - start, contextCount = contextEnd -
contextStart
.
Parameters | |
---|---|
text |
char : 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
public void drawTextRun (CharSequence text, int start, int end, int contextStart, int contextEnd, float x, float y, boolean isRtl, Paint paint)
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 Paint.getRunAdvance(char, int, int, int, int, boolean, int)
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 . |
drawVertices
public void 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)
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 |
float : This value cannot be null . |
vertOffset |
int : Number of values in the verts to skip before drawing. |
texs |
float : This value may be null . |
texOffset |
int : Number of values in texs to skip before drawing. |
colors |
int : This value may be null . |
colorOffset |
int : Number of values in colors to skip before drawing. |
indices |
short : This value may be null . |
indexOffset |
int |
indexCount |
int : Number of entries in the indices array (if not null). |
paint |
Paint : This value cannot be null . |
enableZ
public void enableZ ()
Enables Z support which defaults to disabled. This allows for RenderNodes drawn with
drawRenderNode(android.graphics.RenderNode)
to be re-arranged based off of their
RenderNode.getElevation()
and RenderNode.getTranslationZ()
values. It also enables rendering of shadows for RenderNodes with an elevation or
translationZ.
Any draw reordering will not be moved before this call. A typical usage of this might look something like:
void draw(Canvas canvas) { // Draw any background content canvas.drawColor(backgroundColor); // Begin drawing that may be reordered based off of Z canvas.enableZ(); for (RenderNode child : children) { canvas.drawRenderNode(child); } // End drawing that may be reordered based off of Z canvas.disableZ(); // Draw any overlays canvas.drawText("I'm on top of everything!", 0, 0, paint); }
save()
or restore()
calls as it is not
considered to be part of the current matrix or clip.
See disableZ()
getHeight
public int getHeight ()
Returns the height of the current drawing layer
Returns | |
---|---|
int |
the height of the current drawing layer |
getMaximumBitmapHeight
public int getMaximumBitmapHeight ()
Returns the maximum allowed height for bitmaps drawn with this canvas. Attempting to draw with a bitmap taller than this value will result in an error.
Returns | |
---|---|
int |
getMaximumBitmapWidth
public int getMaximumBitmapWidth ()
Returns the maximum allowed width for bitmaps drawn with this canvas. Attempting to draw with a bitmap wider than this value will result in an error.
Returns | |
---|---|
int |
getWidth
public int getWidth ()
Returns the width of the current drawing layer
Returns | |
---|---|
int |
the width of the current drawing layer |
isHardwareAccelerated
public boolean isHardwareAccelerated ()
Indicates whether this Canvas uses hardware acceleration. Note that this method does not define what type of hardware acceleration may or may not be used.
Returns | |
---|---|
boolean |
True if drawing operations are hardware accelerated, false otherwise. |
isOpaque
public boolean isOpaque ()
Return true if the device that the current layer draws into is opaque (that is, it does not support per-pixel alpha).
Returns | |
---|---|
boolean |
true if the device that the current layer draws into is opaque |
setBitmap
public void setBitmap (Bitmap bitmap)
Specify a bitmap for the canvas to draw into. All canvas state such as
layers, filters, and the save/restore stack are reset. Additionally,
the canvas' target density is updated to match that of the bitmap.
Prior to API level android.os.Build.VERSION_CODES.O Build.VERSION_CODES.O
the current matrix and
clip stack were preserved.
Parameters | |
---|---|
bitmap |
Bitmap : Specifies a mutable bitmap for the canvas to draw into.
This value may be null . |
setDensity
public void setDensity (int density)
Specifies the density for this Canvas' backing bitmap. This modifies
the target density of the canvas itself, as well as the density of its
backing bitmap via Bitmap.setDensity(int)
.
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. |