Canvas

public class Canvas
extends Object



The Canvas class holds the "draw" calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing).

Developer Guides

For more information about how to use Canvas, read the Canvas and Drawables developer guide.

Summary

Nested classes

enum Canvas.EdgeType

This enum was deprecated in API level 30. quickReject no longer uses this.

enum Canvas.VertexMode

Constants

int ALL_SAVE_FLAG

Restore everything when restore() is called (standard save flags).

Public constructors

Canvas()

Construct an empty raster canvas.

Canvas(Bitmap bitmap)

Construct a canvas with the specified bitmap to draw into.

Public methods

boolean clipOutPath(Path path)

Set the clip to the difference of the current clip and the specified path.

boolean clipOutRect(int left, int top, int right, int bottom)

Set the clip to the difference of the current clip and the specified rectangle, which is expressed in local coordinates.

boolean clipOutRect(Rect rect)

Set the clip to the difference of the current clip and the specified rectangle, which is expressed in local coordinates.

boolean clipOutRect(float left, float top, float right, float bottom)

Set the clip to the difference of the current clip and the specified rectangle, which is expressed in local coordinates.

boolean clipOutRect(RectF rect)

Set the clip to the difference of the current clip and the specified rectangle, which is expressed in local coordinates.

boolean clipPath(Path path, Region.Op op)

This method was deprecated in API level 26. Region.Op values other than Region.Op#INTERSECT and Region.Op#DIFFERENCE have the ability to expand the clip. The canvas clipping APIs are intended to only expand the clip as a result of a restore operation. This enables a view parent to clip a canvas to clearly define the maximal drawing area of its children. The recommended alternative calls are clipPath(android.graphics.Path) and clipOutPath(android.graphics.Path); As of API Level API level android.os.Build.VERSION_CODES.P Build.VERSION_CODES.P only Region.Op#INTERSECT and Region.Op#DIFFERENCE are valid Region.Op parameters.

boolean clipPath(Path path)

Intersect the current clip with the specified path.

boolean clipRect(float left, float top, float right, float bottom, Region.Op op)

This method was deprecated in API level 26. Region.Op values other than Region.Op#INTERSECT and Region.Op#DIFFERENCE have the ability to expand the clip. The canvas clipping APIs are intended to only expand the clip as a result of a restore operation. This enables a view parent to clip a canvas to clearly define the maximal drawing area of its children. The recommended alternative calls are clipRect(float, float, float, float) and clipOutRect(float, float, float, float); As of API Level API level android.os.Build.VERSION_CODES.P Build.VERSION_CODES.P only Region.Op#INTERSECT and Region.Op#DIFFERENCE are valid Region.Op parameters.

boolean clipRect(RectF rect)

Intersect the current clip with the specified rectangle, which is expressed in local coordinates.

boolean clipRect(Rect rect)

Intersect the current clip with the specified rectangle, which is expressed in local coordinates.

boolean clipRect(Rect rect, Region.Op op)

This method was deprecated in API level 26. Region.Op values other than Region.Op#INTERSECT and Region.Op#DIFFERENCE have the ability to expand the clip. The canvas clipping APIs are intended to only expand the clip as a result of a restore operation. This enables a view parent to clip a canvas to clearly define the maximal drawing area of its children. The recommended alternative calls are clipRect(android.graphics.Rect) and clipOutRect(android.graphics.Rect); As of API Level API level android.os.Build.VERSION_CODES.P Build.VERSION_CODES.P only Region.Op#INTERSECT and Region.Op#DIFFERENCE are valid Region.Op parameters.

boolean clipRect(int left, int top, int right, int bottom)

Intersect the current clip with the specified rectangle, which is expressed in local coordinates.

boolean clipRect(float left, float top, float right, float bottom)

Intersect the current clip with the specified rectangle, which is expressed in local coordinates.

boolean clipRect(RectF rect, Region.Op op)

This method was deprecated in API level 26. Region.Op values other than Region.Op#INTERSECT and Region.Op#DIFFERENCE have the ability to expand the clip. The canvas clipping APIs are intended to only expand the clip as a result of a restore operation. This enables a view parent to clip a canvas to clearly define the maximal drawing area of its children. The recommended alternative calls are clipRect(android.graphics.RectF) and clipOutRect(android.graphics.RectF); As of API Level API level android.os.Build.VERSION_CODES.P Build.VERSION_CODES.P only Region.Op#INTERSECT and Region.Op#DIFFERENCE are valid Region.Op parameters.

void concat(Matrix matrix)

Preconcat the current matrix with the specified matrix.

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 was deprecated in API level 21. Usage with a hardware accelerated canvas requires an internal copy of color buffer contents every time this method is called. Using a Bitmap avoids this copy, and allows the application to more explicitly control the lifetime and copies of pixel data.

void drawBitmap(int[] colors, int offset, int stride, int x, int y, int width, int height, boolean hasAlpha, Paint paint)

This method was deprecated in API level 21. Usage with a hardware accelerated canvas requires an internal copy of color buffer contents every time this method is called. Using a Bitmap avoids this copy, and allows the application to more explicitly control the lifetime and copies of pixel data.

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, Rect src, RectF 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 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(long color)

Fill the entire canvas' bitmap (restricted to the current clip) with the specified color, using srcover porterduff mode.

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 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.)

void drawPatch(NinePatch patch, Rect dst, Paint paint)

Draws the specified bitmap as an N-patch (most often, a 9-patch.)

void drawPath(Path path, Paint paint)

Draw the specified path using the specified paint.

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 drawPicture(Picture picture, Rect dst)

Draw the picture, stretched to fit into the dst rectangle.

void drawPoint(float x, float y, Paint paint)

Helper for drawPoints() for drawing a single point.

void drawPoints(float[] pts, Paint paint)

Helper for drawPoints() that assumes you want to draw the entire array

void drawPoints(float[] pts, int offset, int count, Paint paint)

Draw a series of points.

void drawPosText(String text, float[] pos, Paint paint)

This method was deprecated in API level 16. This method does not support glyph composition and decomposition and should therefore not be used to render complex scripts. It also doesn't handle supplementary characters (eg emoji).

void drawPosText(char[] text, int index, int count, float[] pos, Paint paint)

This method was deprecated in API level 16. This method does not support glyph composition and decomposition and should therefore not be used to render complex scripts. It also doesn't handle supplementary characters (eg emoji).

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 drawRenderNode(RenderNode renderNode)

Draws the given RenderNode.

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(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 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 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 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 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.

boolean getClipBounds(Rect bounds)

Return the bounds of the current clip (in local coordinates) in the bounds parameter, and return true if it is non-empty.

final Rect getClipBounds()

Retrieve the bounds of the current clip (in local coordinates).

int getDensity()

Returns the target density of the canvas.

DrawFilter getDrawFilter()
int getHeight()

Returns the height of the current drawing layer

void getMatrix(Matrix ctm)

This method was deprecated in API level 16. Hardware accelerated canvases may have any matrix when passed to a View or Drawable, as it is implementation defined where in the hierarchy such canvases are created. It is recommended in such cases to either draw contents irrespective of the current matrix, or to track relevant transform state outside of the canvas.

final Matrix getMatrix()

This method was deprecated in API level 16. Hardware accelerated canvases may have any matrix when passed to a View or Drawable, as it is implementation defined where in the hierarchy such canvases are created. It is recommended in such cases to either draw contents irrespective of the current matrix, or to track relevant transform state outside of the canvas.

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 getSaveCount()

Returns the number of matrix/clip states on the Canvas' private stack.

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 (i.e.

boolean quickReject(float left, float top, float right, float bottom, Canvas.EdgeType type)

This method was deprecated in API level 30. The EdgeType is ignored. Use quickReject(float, float, float, float) instead.

boolean quickReject(Path path)

Return true if the specified path, after being transformed by the current matrix, would lie completely outside of the current clip.

boolean quickReject(RectF rect)

Return true if the specified rectangle, after being transformed by the current matrix, would lie completely outside of the current clip.

boolean quickReject(RectF rect, Canvas.EdgeType type)

This method was deprecated in API level 30. The EdgeType is ignored. Use quickReject(android.graphics.RectF) instead.

boolean quickReject(Path path, Canvas.EdgeType type)

This method was deprecated in API level 30. The EdgeType is ignored. Use quickReject(android.graphics.Path) instead.

boolean quickReject(float left, float top, float right, float bottom)

Return true if the specified rectangle, after being transformed by the current matrix, would lie completely outside of the current clip.

void restore()

This call balances a previous call to save(), and is used to remove all modifications to the matrix/clip state since the last save call.

void restoreToCount(int saveCount)

Efficient way to pop any calls to save() that happened after the save count reached saveCount.

void rotate(float degrees)

Preconcat the current matrix with the specified rotation.

final void rotate(float degrees, float px, float py)

Preconcat the current matrix with the specified rotation.

int save()

Saves the current matrix and clip onto a private stack.

int saveLayer(RectF bounds, Paint paint, int saveFlags)

This method was deprecated in API level 26. Use saveLayer(android.graphics.RectF, android.graphics.Paint) instead.

int saveLayer(RectF bounds, Paint paint)

This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen rendering target.

int saveLayer(float left, float top, float right, float bottom, Paint paint)

Convenience for saveLayer(android.graphics.RectF, android.graphics.Paint) that takes the four float coordinates of the bounds rectangle.

int saveLayer(float left, float top, float right, float bottom, Paint paint, int saveFlags)

This method was deprecated in API level 26. Use saveLayer(float, float, float, float, android.graphics.Paint) instead.

int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, int saveFlags)

This method was deprecated in API level 26. Use saveLayerAlpha(float, float, float, float, int) instead.

int saveLayerAlpha(RectF bounds, int alpha)

Convenience for saveLayer(android.graphics.RectF, android.graphics.Paint) but instead of taking a entire Paint object it takes only the alpha parameter.

int saveLayerAlpha(RectF bounds, int alpha, int saveFlags)

This method was deprecated in API level 26. Use saveLayerAlpha(android.graphics.RectF, int) instead.

int saveLayerAlpha(float left, float top, float right, float bottom, int alpha)

Convenience for saveLayerAlpha(android.graphics.RectF, int) that takes the four float coordinates of the bounds rectangle.

final void scale(float sx, float sy, float px, float py)

Preconcat the current matrix with the specified scale.

void scale(float sx, float sy)

Preconcat the current matrix with the specified scale.

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.

void setDrawFilter(DrawFilter filter)
void setMatrix(Matrix matrix)

Completely replace the current matrix with the specified matrix.

void skew(float sx, float sy)

Preconcat the current matrix with the specified skew.

void translate(float dx, float dy)

Preconcat the current matrix with the specified translation

Inherited methods

From class java.lang.Object

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeout, int nanos)

Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

final void wait(long timeout)

Causes the current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.

final void wait()

Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.

Constants

ALL_SAVE_FLAG

public static final int ALL_SAVE_FLAG

Restore everything when restore() is called (standard save flags).

Note: for performance reasons, it is strongly recommended to pass this - the complete set of flags - to any call to saveLayer() and saveLayerAlpha() variants.

Note: all methods that accept this flag have flagless versions that are equivalent to passing this flag.

Constant Value: 31 (0x0000001f)

Public constructors

Canvas

public Canvas ()

Construct an empty raster canvas. Use setBitmap() to specify a bitmap to draw into. The initial target density is Bitmap#DENSITY_NONE; this will typically be replaced when a target bitmap is set for the canvas.

Canvas

public Canvas (Bitmap bitmap)

Construct a canvas with the specified bitmap to draw into. The bitmap must be mutable.

The initial target density of the canvas is the same as the given bitmap's density.

Parameters
bitmap Bitmap: Specifies a mutable bitmap for the canvas to draw into. This value cannot be null.

Public methods

clipOutPath

public boolean clipOutPath (Path path)

Set the clip to the difference of the current clip and the specified path.

Parameters
path Path: The path used in the difference operation This value cannot be null.
Returns
boolean true if the resulting clip is non-empty

clipOutRect

public boolean clipOutRect (int left,                  int top,                  int right,                  int bottom)

Set the clip to the difference of the current clip and the specified rectangle, which is expressed in local coordinates.

Parameters
left int: The left side of the rectangle used in the difference operation
top int: The top of the rectangle used in the difference operation
right int: The right side of the rectangle used in the difference operation
bottom int: The bottom of the rectangle used in the difference operation
Returns
boolean true if the resulting clip is non-empty

clipOutRect

public boolean clipOutRect (Rect rect)

Set the clip to the difference of the current clip and the specified rectangle, which is expressed in local coordinates.

Parameters
rect Rect: The rectangle to perform a difference op with the current clip. This value cannot be null.
Returns
boolean true if the resulting clip is non-empty

clipOutRect

public boolean clipOutRect (float left,                  float top,                  float right,                  float bottom)

Set the clip to the difference of the current clip and the specified rectangle, which is expressed in local coordinates.

Parameters
left float: The left side of the rectangle used in the difference operation
top float: The top of the rectangle used in the difference operation
right float: The right side of the rectangle used in the difference operation
bottom float: The bottom of the rectangle used in the difference operation
Returns
boolean true if the resulting clip is non-empty

clipOutRect

public boolean clipOutRect (RectF rect)

Set the clip to the difference of the current clip and the specified rectangle, which is expressed in local coordinates.

Parameters
rect RectF: The rectangle to perform a difference op with the current clip. This value cannot be null.
Returns
boolean true if the resulting clip is non-empty

clipPath

public boolean clipPath (Path path)

Intersect the current clip with the specified path.

Parameters
path Path: The path to intersect with the current clip This value cannot be null.
Returns
boolean true if the resulting clip is non-empty

clipRect

public boolean clipRect (float left,                  float top,                  float right,                  float bottom,                  Region.Op op)

This method was deprecated in API level 26.
Region.Op values other than Region.Op#INTERSECT and Region.Op#DIFFERENCE have the ability to expand the clip. The canvas clipping APIs are intended to only expand the clip as a result of a restore operation. This enables a view parent to clip a canvas to clearly define the maximal drawing area of its children. The recommended alternative calls are clipRect(float, float, float, float) and clipOutRect(float, float, float, float); As of API Level API level android.os.Build.VERSION_CODES.P Build.VERSION_CODES.P only Region.Op#INTERSECT and Region.Op#DIFFERENCE are valid Region.Op parameters.

Modify the current clip with the specified rectangle, which is expressed in local coordinates.

Parameters
left float: The left side of the rectangle to intersect with the current clip
top float: The top of the rectangle to intersect with the current clip
right float: The right side of the rectangle to intersect with the current clip
bottom float: The bottom of the rectangle to intersect with the current clip
op Region.Op: How the clip is modified This value cannot be null.
Returns
boolean true if the resulting clip is non-empty

clipRect

public boolean clipRect (RectF rect)

Intersect the current clip with the specified rectangle, which is expressed in local coordinates.

Parameters
rect RectF: The rectangle to intersect with the current clip. This value cannot be null.
Returns
boolean true if the resulting clip is non-empty

clipRect

public boolean clipRect (Rect rect)

Intersect the current clip with the specified rectangle, which is expressed in local coordinates.

Parameters
rect Rect: The rectangle to intersect with the current clip. This value cannot be null.
Returns
boolean true if the resulting clip is non-empty

clipRect

public boolean clipRect (int left,                  int top,                  int right,                  int bottom)

Intersect the current clip with the specified rectangle, which is expressed in local coordinates.

Parameters
left int: The left side of the rectangle to intersect with the current clip
top int: The top of the rectangle to intersect with the current clip
right int: The right side of the rectangle to intersect with the current clip
bottom int: The bottom of the rectangle to intersect with the current clip
Returns
boolean true if the resulting clip is non-empty

clipRect

public boolean clipRect (float left,                  float top,                  float right,                  float bottom)

Intersect the current clip with the specified rectangle, which is expressed in local coordinates.

Parameters
left float: The left side of the rectangle to intersect with the current clip
top float: The top of the rectangle to intersect with the current clip
right float: The right side of the rectangle to intersect with the current clip
bottom float: The bottom of the rectangle to intersect with the current clip
Returns
boolean true if the resulting clip is non-empty

concat

public void concat (Matrix matrix)

Preconcat the current matrix with the specified matrix. If the specified matrix is null, this method does nothing.

Parameters
matrix Matrix: The matrix to preconcatenate with the current matrix This value may be null.

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: The paint used to draw the arc 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: The bounds of oval used to define the shape and size of the arc 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: The paint used to draw the arc 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: The bitmap to draw This value cannot be null.
matrix Matrix: The matrix used to transform the bitmap when it is drawn This value cannot be null.
paint Paint: May be null. The paint used to draw the bitmap 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 was deprecated in API level 21.
Usage with a hardware accelerated canvas requires an internal copy of color buffer contents every time this method is called. Using a Bitmap avoids this copy, and allows the application to more explicitly control the lifetime and copies of pixel data.

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: Array of colors representing the pixels of the bitmap 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: May be null. The paint used to draw the bitmap 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 was deprecated in API level 21.
Usage with a hardware accelerated canvas requires an internal copy of color buffer contents every time this method is called. Using a Bitmap avoids this copy, and allows the application to more explicitly control the lifetime and copies of pixel data.

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: The bitmap to be drawn This value cannot be null.
src Rect: May be null. The subset of the bitmap to be drawn This value may be null.
dst Rect: The rectangle that the bitmap will be scaled/translated to fit into This value cannot be null.
paint Paint: May be null. The paint used to draw the bitmap 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: The bitmap to be drawn This value cannot be null.
src Rect: May be null. The subset of the bitmap to be drawn This value may be null.
dst RectF: The rectangle that the bitmap will be scaled/translated to fit into This value cannot be null.
paint Paint: May be null. The paint used to draw the bitmap 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: The bitmap to be drawn 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: The paint used to draw the bitmap (may be null) 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.

Parameters
bitmap Bitmap: The bitmap to draw using the mesh 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: Array of x,y pairs, specifying where the mesh should be drawn. There must be at least (meshWidth+1) * (meshHeight+1) * 2 + vertOffset values in the array This value cannot be null.
vertOffset int: Number of verts elements to skip before drawing
colors int: May be null. Specifies a color at each vertex, which is interpolated across the cell, and whose values are multiplied by the corresponding bitmap colors. If not null, there must be at least (meshWidth+1) * (meshHeight+1) + colorOffset values in the array. This value may be null.
colorOffset int: Number of color elements to skip before drawing
paint Paint: May be null. The paint used to draw the bitmap 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: The paint used to draw the circle 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 ColorLongs.
mode BlendMode: the blendmode to apply to the color This value cannot be null.
Throws
IllegalArgumentException if the color space encoded in the ColorLong is invalid or unknown.

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: the blendmode to apply to the color This value cannot be null.

drawColor

public void drawColor (long color)

Fill the entire canvas' bitmap (restricted to the current clip) with the specified color, using srcover porterduff mode.

Parameters
color long: the ColorLong to draw onto the canvas. See the Color class for details about ColorLongs.
Throws
IllegalArgumentException if the color space encoded in the ColorLong is invalid or unknown.

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: the porter-duff mode to apply to the color 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: The outer rectangular bounds of the roundRect to be drawn This value cannot be null.
outerRadii float: Array of 8 float representing the x, y corner radii for top left, top right, bottom right, bottom left corners respectively on the outer rounded rectangle This value cannot be null.
inner RectF: The inner rectangular bounds of the roundRect to be drawn This value cannot be null.
innerRadii float: Array of 8 float representing the x, y corner radii for top left, top right, bottom right, bottom left corners respectively on the outer rounded rectangle This value cannot be null.
paint Paint: The paint used to draw the double roundRect 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: The outer rectangular bounds of the roundRect to be drawn 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: The inner rectangular bounds of the roundRect to be drawn 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: The paint used to draw the double roundRect 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: Array of glyph IDs. The length of array must be greater than or equal to glyphIdOffset + glyphCount. This value cannot be null.
glyphIdOffset int: Number of elements to skip before drawing in glyphIds array. Value is 0 or greater
positions float: A flattened X and Y position array. The first glyph X position must be stored at positionOffset. The first glyph Y position must be stored at positionOffset + 1, then the second glyph X position must be stored at positionOffset + 2. The length of array must be greater than or equal to positionOffset + glyphCount * 2. This value cannot be null.
positionOffset int: Number of elements to skip before drawing in positions. The first glyph X position must be stored at positionOffset. The first glyph Y position must be stored at positionOffset + 1, then the second glyph X position must be stored at positionOffset + 2. Value is 0 or greater
glyphCount int: Number of glyphs to be drawn. Value is 0 or greater
font Font: Font used for drawing. This value cannot be null.
paint Paint: Paint used for drawing. The typeface set to this paint is ignored. 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: The paint used to draw the line 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: Array of points to draw [x0 y0 x1 y1 x2 y2 ...] 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: The paint used to draw the points 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.

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: The rectangle bounds of the oval to be drawn 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: The paint used to draw onto the canvas 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.)

Parameters
patch NinePatch: The ninepatch object to render This value cannot be null.
dst RectF: The destination rectangle. This value cannot be null.
paint Paint: The paint to draw the bitmap with. may be null 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.)

Parameters
patch NinePatch: The ninepatch object to render This value cannot be null.
dst Rect: The destination rectangle. This value cannot be null.
paint Paint: The paint to draw the bitmap with. may be null 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: The path to be drawn This value cannot be null.
paint Paint: The paint used to draw the path 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

0 Response to "Draw Text On Canvas Android"

Post a Comment