Java android.graphics Canvas fields, constructors, methods, implement or subclass

Example usage for Java android.graphics Canvas fields, constructors, methods, implement or subclass

Introduction

In this page you can find the methods, fields and constructors for android.graphics Canvas.

The text is from its open source code.

Field

intMATRIX_SAVE_FLAG
Restore the current matrix when restore() is called.
intCLIP_SAVE_FLAG
Restore the current clip when restore() is called.
intHAS_ALPHA_LAYER_SAVE_FLAG
The layer requires a per-pixel alpha channel.
intFULL_COLOR_LAYER_SAVE_FLAG
The layer requires full 8-bit precision for each color channel.
intCLIP_TO_LAYER_SAVE_FLAG
Clip drawing to the bounds of the offscreen layer, omit at your own peril.
intALL_SAVE_FLAG
Restore everything when restore() is called (standard save flags).

Constructor

Canvas(@NonNull Bitmap bitmap)
Construct a canvas with the specified bitmap to draw into.
Canvas(long nativeCanvas)
Canvas()
Construct an empty raster canvas.

Method

booleanclipPath(@NonNull Path path)
Intersect the current clip with the specified path.
booleanclipPath(@NonNull Path path, @NonNull Region.Op op)
Modify the current clip with the specified path.
booleanclipRect(float left, float top, float right, float bottom)
Intersect the current clip with the specified rectangle, which is expressed in local coordinates.
booleanclipRect(int left, int top, int right, int bottom)
Intersect the current clip with the specified rectangle, which is expressed in local coordinates.
booleanclipRect(@NonNull RectF rect)
Intersect the current clip with the specified rectangle, which is expressed in local coordinates.
booleanclipRect(@NonNull Rect rect)
Intersect the current clip with the specified rectangle, which is expressed in local coordinates.
booleanclipRect(@NonNull RectF rect, @NonNull Region.Op op)
Modify the current clip with the specified rectangle.
booleanclipRect(@NonNull Rect rect, @NonNull Region.Op op)
Modify the current clip with the specified rectangle, which is expressed in local coordinates.
booleanclipRect(float left, float top, float right, float bottom, @NonNull Region.Op op)
Modify the current clip with the specified rectangle, which is expressed in local coordinates.
booleanclipRegion(@NonNull Region region)
Intersect the current clip with the specified region.
voidconcat(@Nullable Matrix matrix)
Preconcat the current matrix with the specified matrix.
voiddrawArc(@NonNull RectF oval, float startAngle, float sweepAngle, boolean useCenter, @NonNull Paint paint)

Draw the specified arc, which will be scaled to fit inside the specified oval.

voiddrawARGB(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.
voiddrawBitmap(@NonNull Bitmap bitmap, float left, float top, @Nullable Paint paint)
Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix.
voiddrawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull RectF dst, @Nullable Paint paint)
Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle.
voiddrawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull Rect dst, @Nullable Paint paint)
Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle.
voiddrawBitmap(@NonNull Bitmap bitmap, @NonNull Matrix matrix, @Nullable Paint paint)
Draw the bitmap using the specified matrix.
voiddrawBitmapMesh(@NonNull Bitmap bitmap, int meshWidth, int meshHeight, @NonNull float[] verts, int vertOffset, @Nullable int[] colors, int colorOffset, @Nullable Paint paint)
Draw the bitmap through the mesh, where mesh vertices are evenly distributed across the bitmap.
voiddrawCircle(float cx, float cy, float radius, @NonNull Paint paint)
Draw the specified circle using the specified paint.
voiddrawColor(@ColorInt int color, @NonNull PorterDuff.Mode mode)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and porter-duff xfermode.
voiddrawColor(@ColorInt int color)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified color, using srcover porterduff mode.
voiddrawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint)
Draw a line segment with the specified start and stop x,y coordinates, using the specified paint.
voiddrawLines(@Size(multiple = 4) @NonNull float[] pts, @NonNull Paint paint)
voiddrawLines(@Size(multiple = 4) @NonNull float[] pts, int offset, int count, @NonNull Paint paint)
Draw a series of lines.
voiddrawOval(@NonNull RectF oval, @NonNull Paint paint)
Draw the specified oval using the specified paint.
voiddrawOval(float left, float top, float right, float bottom, @NonNull Paint paint)
Draw the specified oval using the specified paint.
voiddrawPaint(@NonNull Paint paint)
Fill the entire canvas' bitmap (restricted to the current clip) with the specified paint.
voiddrawPath(@NonNull Path path, @NonNull Paint paint)
Draw the specified path using the specified paint.
voiddrawPicture(@NonNull Picture picture)
Save the canvas state, draw the picture, and restore the canvas state.
voiddrawPoint(float x, float y, @NonNull Paint paint)
Helper for drawPoints() for drawing a single point.
voiddrawRect(float left, float top, float right, float bottom, @NonNull Paint paint)
Draw the specified Rect using the specified paint.
voiddrawRect(@NonNull RectF rect, @NonNull Paint paint)
Draw the specified Rect using the specified paint.
voiddrawRect(@NonNull Rect r, @NonNull Paint paint)
Draw the specified Rect using the specified Paint.
voiddrawRGB(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.
voiddrawRoundRect(@NonNull RectF rect, float rx, float ry, @NonNull Paint paint)
Draw the specified round-rect using the specified paint.
voiddrawText(@NonNull String text, float x, float y, @NonNull Paint paint)
Draw the text, with origin at (x,y), using the specified paint.
voiddrawText(@NonNull char[] text, int index, int count, float x, float y, @NonNull Paint paint)
Draw the text, with origin at (x,y), using the specified paint.
voiddrawText(@NonNull String text, int start, int end, float x, float y, @NonNull Paint paint)
Draw the text, with origin at (x,y), using the specified paint.
voiddrawText(@NonNull CharSequence text, int start, int end, float x, float y, @NonNull Paint paint)
Draw the specified range of text, specified by start/end, with its origin at (x,y), in the specified Paint.
voiddrawTextOnPath(@NonNull String text, @NonNull Path path, float hOffset, float vOffset, @NonNull Paint paint)
Draw the text, with origin at (x,y), using the specified paint, along the specified path.
booleangetClipBounds(@Nullable Rect bounds)
Return the bounds of the current clip (in local coordinates) in the bounds parameter, and return true if it is non-empty.
RectgetClipBounds()
Retrieve the bounds of the current clip (in local coordinates).
intgetHeight()
Returns the height of the current drawing layer
voidgetMatrix(@NonNull Matrix ctm)
Return, in ctm, the current transformation matrix.
intgetMaximumBitmapHeight()
Returns the maximum allowed height for bitmaps drawn with this canvas.
intgetMaximumBitmapWidth()
Returns the maximum allowed width for bitmaps drawn with this canvas.
intgetSaveCount()
Returns the number of matrix/clip states on the Canvas' private stack.
intgetWidth()
Returns the width of the current drawing layer
booleanisHardwareAccelerated()
Indicates whether this Canvas uses hardware acceleration.
voidrestore()
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.
voidrestoreToCount(int saveCount)
Efficient way to pop any calls to save() that happened after the save count reached saveCount.
voidrotate(float degrees, float px, float py)
Preconcat the current matrix with the specified rotation.
voidrotate(float degrees)
Preconcat the current matrix with the specified rotation.
intsave()
Saves the current matrix and clip onto a private stack.
intsave(@Saveflags int saveFlags)
Based on saveFlags, can save the current matrix and clip onto a private stack.
intsaveLayer(@Nullable RectF bounds, @Nullable Paint paint, @Saveflags int saveFlags)
This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen bitmap.
intsaveLayer(float left, float top, float right, float bottom, @Nullable Paint paint, @Saveflags int saveFlags)
Helper version of saveLayer() that takes 4 values rather than a RectF.
intsaveLayerAlpha(float left, float top, float right, float bottom, int alpha, @Saveflags int saveFlags)
Helper for saveLayerAlpha() that takes 4 values instead of a RectF.
intsaveLayerAlpha(@Nullable RectF bounds, int alpha, @Saveflags int saveFlags)
This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen bitmap.
voidscale(float sx, float sy)
Preconcat the current matrix with the specified scale.
voidscale(float sx, float sy, float px, float py)
Preconcat the current matrix with the specified scale.
voidsetBitmap(@Nullable Bitmap bitmap)
Specify a bitmap for the canvas to draw into.
voidsetDensity(int density)

Specifies the density for this Canvas' backing bitmap.

voidsetDrawFilter(@Nullable DrawFilter filter)
voidsetMatrix(@Nullable Matrix matrix)
Completely replace the current matrix with the specified matrix.
voidtranslate(float dx, float dy)
Preconcat the current matrix with the specified translation