Canvas Class

Definition

The Canvas class holds the "draw" calls.

[Android.Runtime.Register("android/graphics/Canvas", DoNotGenerateAcw=true)]
public class Canvas : Java.Lang.Object
[<Android.Runtime.Register("android/graphics/Canvas", DoNotGenerateAcw=true)>]
type Canvas = class
    inherit Object
Inheritance
Canvas
Derived
Attributes

Remarks

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

<div class="special reference"> <h3>Developer Guides</h3>

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

</div>

Java documentation for android.graphics.Canvas.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Canvas()

Construct an empty raster canvas.

Canvas(Bitmap)

Construct a canvas with the specified bitmap to draw into.

Canvas(IGL)
Canvas(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
ClipBounds

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

Density

Returns the target density of the canvas. -or- Specifies the density for this Canvas' backing bitmap.

DrawFilter
GL
Handle

The handle to the underlying Android instance.

(Inherited from Object)
Height

Returns the height of the current drawing layer

IsHardwareAccelerated

Indicates whether this Canvas uses hardware acceleration.

IsOpaque

Return true if the device that the current layer draws into is opaque (that is, it does not support per-pixel alpha).

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
Matrix
Obsolete.

Return a new matrix with a copy of the canvas' current transformation matrix. -or- Completely replace the current matrix with the specified matrix.

MaximumBitmapHeight

Returns the maximum allowed height for bitmaps drawn with this canvas.

MaximumBitmapWidth

Returns the maximum allowed width for bitmaps drawn with this canvas.

PeerReference (Inherited from Object)
SaveCount

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

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Width

Returns the width of the current drawing layer

Methods

ClipOutPath(Path)

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

ClipOutRect(Int32, Int32, Int32, Int32)

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

ClipOutRect(Rect)

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

ClipOutRect(RectF)

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

ClipOutRect(Single, Single, Single, Single)

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

ClipPath(Path)

Intersect the current clip with the specified path.

ClipPath(Path, Region+Op)

Intersect the current clip with the specified path.

ClipRect(Int32, Int32, Int32, Int32)

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

ClipRect(Rect)

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

ClipRect(Rect, Region+Op)

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

ClipRect(RectF)

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

ClipRect(RectF, Region+Op)

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

ClipRect(Single, Single, Single, Single)

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

ClipRect(Single, Single, Single, Single, Region+Op)

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

ClipRegion(Region)
Obsolete.

Intersect the current clip with the specified region.

ClipRegion(Region, Region+Op)
Obsolete.

Modify the current clip with the specified region.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Concat(Matrix)

Preconcat the current matrix with the specified matrix.

DisableZ()

Disables Z support, preventing any RenderNodes drawn after this point from being visually reordered or having shadows rendered.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
DrawArc(RectF, Single, Single, Boolean, Paint)

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

DrawArc(Single, Single, Single, Single, Single, Single, Boolean, Paint)

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

DrawARGB(Int32, Int32, Int32, Int32)

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

DrawBitmap(Bitmap, Matrix, Paint)

Draw the bitmap using the specified matrix.

DrawBitmap(Bitmap, Rect, Rect, Paint)

Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle.

DrawBitmap(Bitmap, Rect, RectF, Paint)

Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle.

DrawBitmap(Bitmap, Single, Single, Paint)

Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix.

DrawBitmap(Int32[], Int32, Int32, Int32, Int32, Int32, Int32, Boolean, Paint)
Obsolete.

Legacy version of drawBitmap(int[] colors, .

DrawBitmap(Int32[], Int32, Int32, Single, Single, Int32, Int32, Boolean, Paint)
Obsolete.

Treat the specified array of colors as a bitmap, and draw it.

DrawBitmapMesh(Bitmap, Int32, Int32, Single[], Int32, Int32[], Int32, Paint)

Draw the bitmap through the mesh, where mesh vertices are evenly distributed across the bitmap.

DrawCircle(Single, Single, Single, Paint)

Draw the specified circle using the specified paint.

DrawColor(Color)

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

DrawColor(Color, BlendMode)

Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and blendmode.

DrawColor(Color, PorterDuff+Mode)

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

DrawColor(Int64)

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

DrawColor(Int64, BlendMode)

Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and blendmode.

DrawDoubleRoundRect(RectF, Single, Single, RectF, Single, Single, Paint)

Draws a double rounded rectangle using the specified paint.

DrawDoubleRoundRect(RectF, Single[], RectF, Single[], Paint)

Draws a double rounded rectangle using the specified paint.

DrawGlyphs(Int32[], Int32, Single[], Int32, Int32, Font, Paint)

Draw array of glyphs with specified font.

DrawLine(Single, Single, Single, Single, Paint)

Draw a line segment with the specified start and stop x,y coordinates, using the specified paint.

DrawLines(Single[], Int32, Int32, Paint)

Draw a series of lines.

DrawLines(Single[], Paint)

Draw a series of lines.

DrawMesh(Mesh, BlendMode, Paint)
DrawOval(RectF, Paint)

Draw the specified oval using the specified paint.

DrawOval(Single, Single, Single, Single, Paint)

Draw the specified oval using the specified paint.

DrawPaint(Paint)

Fill the entire canvas' bitmap (restricted to the current clip) with the specified paint.

DrawPatch(NinePatch, Rect, Paint)

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

DrawPatch(NinePatch, RectF, Paint)

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

DrawPath(Path, Paint)

Draw the specified path using the specified paint.

DrawPicture(Picture)

Save the canvas state, draw the picture, and restore the canvas state.

DrawPicture(Picture, Rect)

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

DrawPicture(Picture, RectF)

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

DrawPoint(Single, Single, Paint)

Helper for drawPoints() for drawing a single point.

DrawPoints(Single[], Int32, Int32, Paint)

Draw a series of points.

DrawPoints(Single[], Paint)

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

DrawPosText(Char[], Int32, Int32, Single[], Paint)
Obsolete.

Draw the text in the array, with each character's origin specified by the pos array.

DrawPosText(String, Single[], Paint)
Obsolete.

Draw the text in the array, with each character's origin specified by the pos array.

DrawRect(Rect, Paint)

Draw the specified Rect using the specified Paint.

DrawRect(RectF, Paint)

Draw the specified Rect using the specified paint.

DrawRect(Single, Single, Single, Single, Paint)

Draw the specified Rect using the specified paint.

DrawRenderNode(RenderNode)

Draws the given RenderNode.

DrawRGB(Int32, Int32, Int32)

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

DrawRoundRect(RectF, Single, Single, Paint)

Draw the specified round-rect using the specified paint.

DrawRoundRect(Single, Single, Single, Single, Single, Single, Paint)

Draw the specified round-rect using the specified paint.

DrawText(Char[], Int32, Int32, Single, Single, Paint)

Draw the text, with origin at (x,y), using the specified paint.

DrawText(ICharSequence, Int32, Int32, Single, Single, Paint)

Draw the specified range of text, specified by start/end, with its origin at (x,y), in the specified Paint.

DrawText(String, Int32, Int32, Single, Single, Paint)

Draw the text, with origin at (x,y), using the specified paint.

DrawText(String, Single, Single, Paint)

Draw the text, with origin at (x,y), using the specified paint.

DrawTextOnPath(Char[], Int32, Int32, Path, Single, Single, Paint)

Draw the text, with origin at (x,y), using the specified paint, along the specified path.

DrawTextOnPath(String, Path, Single, Single, Paint)

Draw the text, with origin at (x,y), using the specified paint, along the specified path.

DrawTextRun(Char[], Int32, Int32, Int32, Int32, Single, Single, Boolean, Paint)

Draw a run of text, all in a single direction, with optional context for complex text shaping.

DrawTextRun(ICharSequence, Int32, Int32, Int32, Int32, Single, Single, Boolean, Paint)

Draw a run of text, all in a single direction, with optional context for complex text shaping.

DrawTextRun(MeasuredText, Int32, Int32, Int32, Int32, Single, Single, Boolean, Paint)

Draw a run of text, all in a single direction, with optional context for complex text shaping.

DrawTextRun(String, Int32, Int32, Int32, Int32, Single, Single, Boolean, Paint)

Draw a run of text, all in a single direction, with optional context for complex text shaping.

DrawVertices(Canvas+VertexMode, Int32, Single[], Int32, Single[], Int32, Int32[], Int32, Int16[], Int32, Int32, Paint)

Draw the array of vertices, interpreted as triangles (based on mode).

EnableZ()

Enables Z support which defaults to disabled.

Equals(Object)

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

(Inherited from Object)
FreeGlCaches()
GetClipBounds(Rect)

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

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetMatrix(Matrix)
Obsolete.

Return, in ctm, the current transformation matrix.

JavaFinalize()

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

(Inherited from Object)
Notify()

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

(Inherited from Object)
NotifyAll()

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

(Inherited from Object)
QuickReject(Path)

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

QuickReject(Path, Canvas+EdgeType)

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

QuickReject(RectF)

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

QuickReject(RectF, Canvas+EdgeType)

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

QuickReject(Single, Single, Single, Single)

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

QuickReject(Single, Single, Single, Single, Canvas+EdgeType)

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

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.

RestoreToCount(Int32)

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

Rotate(Single)

Preconcat the current matrix with the specified rotation.

Rotate(Single, Single, Single)

Preconcat the current matrix with the specified rotation.

Save()

Saves the current matrix and clip onto a private stack.

Save(SaveFlags)

Based on saveFlags, can save the current matrix and clip onto a private stack.

SaveLayer(RectF, Paint)

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

SaveLayer(RectF, Paint, SaveFlags)

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

SaveLayer(Single, Single, Single, Single, Paint)

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

SaveLayer(Single, Single, Single, Single, Paint, SaveFlags)

Helper version of saveLayer() that takes 4 values rather than a RectF.

SaveLayerAlpha(RectF, Int32)

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

SaveLayerAlpha(RectF, Int32, SaveFlags)

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

SaveLayerAlpha(Single, Single, Single, Single, Int32)

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

SaveLayerAlpha(Single, Single, Single, Single, Int32, SaveFlags)

Helper for saveLayerAlpha() that takes 4 values instead of a RectF.

Scale(Single, Single)

Preconcat the current matrix with the specified scale.

Scale(Single, Single, Single, Single)

Preconcat the current matrix with the specified scale.

SetBitmap(Bitmap)

Specify a bitmap for the canvas to draw into.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetViewport(Int32, Int32)
Skew(Single, Single)

Preconcat the current matrix with the specified skew.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
Translate(Single, Single)

Preconcat the current matrix with the specified translation

UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to