Canvas
- class Canvas
Canvas
provides an interface for drawing, and how the drawing is clipped and transformed.Canvas
contains a stack ofMatrix
and clip values.Canvas
andPaint
together provide the state to draw intoSurface
orBaseDevice
. EachCanvas
draw call transforms the geometry of the object by the concatenation of allMatrix
values in the stack. The transformed geometry is clipped by the intersection of all of clip values in the stack. TheCanvas
draw calls usePaint
to supply drawing state such as color,Typeface
, text size, stroke width,Shader
and so on.To draw to a pixel-based destination, create raster surface or GPU surface. Request
Canvas
fromSurface
to obtain the interface to draw.Canvas
generated by raster surface draws to memory visible to the CPU.Canvas
generated by GPU surface uses Vulkan or OpenGL to draw to the GPU.To draw to a document, obtain
Canvas
from SVG canvas, document PDF, orPictureRecorder
.Document
basedCanvas
and otherCanvas
subclasses referenceBaseDevice
describing the destination.Canvas
can be constructed to draw toBitmap
without first creating raster surface. This approach may be deprecated in the future.Classes
Canvas.Lattice
dividesBitmap
orImage
into a rectangular grid.Members:
Members:
Members:
SaveLayerRec contains the state used to create the layer.
Members:
Methods
Allocates raster
Canvas
that will draw directly into pixels.Allocates raster
Canvas
specified by inline image specification.Overloaded function.
Returns the pixel base address, and origin if the pixels can be read directly.
Sets the maximum clip rectangle, which can be set by
clipRect()
,clipRRect()
andclipPath()
and intersect the current clip with the specified rect.Overloaded function.
Overloaded function.
Overloaded function.
Overloaded function.
Replaces clip with the intersection or difference of clip and
Region
deviceRgn.Overloaded function.
Makes
Canvas
contents undefined.Associates
Rect
onCanvas
when an annotation; a key-value pair, where the key is an UTF-8 string, and optional value is stored asData
.Draws a set of sprites from atlas, using clip,
Matrix
, and optionalPaint
paint.Draws
Bitmap
bitmap, with its top-left corner at (left, top), using clip,Matrix
, and optionalPaint
paint.Overloaded function.
Overloaded function.
Overloaded function.
Draws
RRect
outer and inner using clip,Matrix
, andPaint
paint.Draws
Image
image, with its top-left corner at (left, top), using clip,Matrix
, and optionalPaint
paint.Overloaded function.
Overloaded function.
Fills clip with
Paint
paint.Draws a Coons patch: the interpolation of four cubics with shared corners, associating a color, and optionally a texture
Point
, with each corner.Draws
Picture
picture, using clip andMatrix
; transforming picture withMatrix
matrix, if provided; and usePaint
paint alpha,ColorFilter
,ImageFilter
, andBlendMode
, if provided.Overloaded function.
Draws
RRect
bounded byRect
rect, with corner radii (rx, ry) using clip,Matrix
, andPaint
paint.Draws text, with origin at (x, y), using clip,
Matrix
,Font
font, andPaint
paint.Draws string, with origin at (x, y), using clip,
Matrix
,Font
font, andPaint
paint.Draws
TextBlob
blob at (x, y), using clip,Matrix
, andPaint
paint.Draws
Vertices
vertices, a triangle mesh, using clip andMatrix
.Triggers the immediate execution of all pending draw operations.
Gets the size of the base or root layer in global canvas coordinates.
Overloaded function.
Overloaded function.
Copies
SurfaceProps
, ifCanvas
is associated with raster surface or GPU surface, and returns true.Returns the number of saved states, each containing:
Matrix
and clip.Sometimes a canvas is owned by a surface.
Legacy version of
getLocalToDevice()
, which strips away any Z information, and just returns a 3x3 version.Returns true if clip is empty; that is, nothing will draw.
Returns true if clip is
Rect
and not empty.Creates
Surface
matching info and props, and associates it withCanvas
.Returns true if
Canvas
has direct access to its pixels.Overloaded function.
Overloaded function.
Sets SkMatrix to the identity matrix.
Removes changes to
Matrix
and clip sinceCanvas
state was last saved.Restores state to
Matrix
and clip values whensave()
,saveLayer()
,saveLayerPreserveLCDTextRequests()
, orsaveLayerAlpha()
returned saveCount.Overloaded function.
Saves
Matrix
and clip.Overloaded function.
Saves
Matrix
and clip, and allocates aBitmap
for subsequent drawing.Scales
Matrix
by sx on the x-axis and sy on the y-axis.Overloaded function.
Skews
Matrix
by sx on the x-axis and sy on the y-axis.Exports a
numpy.ndarray
.Translates
Matrix
by dx along the x-axis and dy along the y-axis.Overloaded function.
Attributes
Methods
- static Canvas.MakeRasterDirect(imageInfo: skia.ImageInfo, pixels: Buffer, rowBytes: int = 0, surfaceProps: SkSurfaceProps = None) skia.Canvas
Allocates raster
Canvas
that will draw directly into pixels.Canvas
is returned if all parameters are valid. Valid parameters include: info dimensions are zero or positive; info containsColorType
andAlphaType
supported by raster surface; pixels is buffer object of sufficient length; rowBytes is zero or large enough to contain info width pixels ofColorType
.Pass zero for rowBytes to compute rowBytes from info width and size of pixel. If rowBytes is greater than zero, it must be equal to or greater than info width times bytes required for
ColorType
.Pixel buffer size should be info height times computed rowBytes. Pixels are not initialized. To access pixels after drawing, call flush() or peekPixels().
- Parameters:
info (skia.ImageInfo) – width, height,
ColorType
,AlphaType
,ColorSpace
, of raster surface; width, or height, or both, may be zeropixels (Union[bytes,bytearray,memoryview]) – destination pixels buffer
rowBytes (int) – interval from one
Surface
row to the next, or zeroprops (skia.SurfaceProps) – LCD striping orientation and setting for device independent fonts; may be None
- static Canvas.MakeRasterDirectN32(width: int, height: int, pixels: Buffer, rowBytes: int = 0) skia.Canvas
Allocates raster
Canvas
specified by inline image specification.Subsequent
Canvas
calls draw into pixels.ColorType
is set toColorType.kN32_ColorType
.AlphaType
is set toAlphaType.kPremul_AlphaType
. To access pixels after drawing, call flush() or peekPixels().Canvas
is returned if all parameters are valid. Valid parameters include: width and height are zero or positive; pixels is buffer object with sufficient length; rowBytes is zero or large enough to contain width pixels ofColorType.kN32_ColorType
.Pass zero for rowBytes to compute rowBytes from width and size of pixel. If rowBytes is greater than zero, it must be equal to or greater than width times bytes required for
ColorType
.Pixel buffer size should be height times rowBytes.
- Parameters:
width (int) – pixel column count on raster surface created; must be zero or greater
height (int) – pixel row count on raster surface created; must be zero or greater
pixels (Union[bytes,bytearray,memoryview]) – pointer to destination pixels buffer; buffer size should be height times rowBytes
rowBytes (int) – interval from one
Surface
row to the next, or zero
- Canvas.__init__(*args, **kwargs)
Overloaded function.
__init__(self: skia.Canvas) -> None
Creates an empty
Canvas
with no backing device or pixels, with a width and height of zero.__init__(self: skia.Canvas, array: numpy.ndarray, colorType: skia.ColorType = skia.ColorType.kN32_ColorType, alphaType: skia.AlphaType = skia.AlphaType.kUnpremul_AlphaType, colorSpace: skia.ColorSpace = None, surfaceProps: SkSurfaceProps = None) -> None
Creates raster
Canvas
backed by numpy array.Subsequent
Canvas
calls draw into pixels. To access pixels after drawing, call flush() or peekPixels().- array:
numpy ndarray of shape=(height, width, channels) and appropriate dtype. Must have non-zero width and height, and the valid number of channels for the specified color type.
- colorType:
color type of the array
- alphaType:
alpha type of the array
- colorSpace:
range of colors; may be nullptr
__init__(self: skia.Canvas, width: int, height: int, props: SkSurfaceProps = None) -> None
Creates
Canvas
of the specified dimensions without aSurface
.Used by subclasses with custom implementations for draw member functions.
If props equals None,
SurfaceProps
are created withSurfaceProps.InitType
settings, which choose the pixel striping direction and order. Since a platform may dynamically change its direction when the device is rotated, and since a platform may have multiple monitors with different characteristics, it is best not to rely on this legacy behavior.- width:
zero or greater
- height:
zero or greater
- props:
LCD striping orientation and setting for device independent fonts; may be None
__init__(self: skia.Canvas, bitmap: skia.Bitmap) -> None
__init__(self: skia.Canvas, bitmap: skia.Bitmap, props: SkSurfaceProps) -> None
Constructs a canvas that draws into bitmap.
Use props to match the device characteristics, like LCD striping.
bitmap is copied so that subsequently editing bitmap will not affect constructed
Canvas
.
- Canvas.accessTopLayerPixels(self: skia.Canvas, origin: skia.IPoint = None) object
Returns the pixel base address, and origin if the pixels can be read directly.
The returned address is only valid while
Canvas
is in scope and unchanged. AnyCanvas
call orSurface
call may invalidate the returned address and other returned values.If pixels are inaccessible, returns None.
- Parameters:
origin – storage for
Canvas
top layer origin, its top-left corner; may be nullptr- Returns:
address of pixels, or nullptr if inaccessible
- Canvas.androidFramework_setDeviceClipRestriction(self: skia.Canvas, rect: skia.IRect) None
Sets the maximum clip rectangle, which can be set by
clipRect()
,clipRRect()
andclipPath()
and intersect the current clip with the specified rect.The maximum clip affects only future clipping operations; it is not retroactive. The clip restriction is not recorded in pictures.
Pass an empty rect to disable maximum clip. This private API is for use by Android framework only.
- Parameters:
rect (skia.IRect) – maximum allowed clip in device coordinates
- Canvas.clear(*args, **kwargs)
Overloaded function.
clear(self: skia.Canvas, color: int) -> None
Fills clip with color color using
BlendMode.kSrc
.This has the effect of replacing all pixels contained by clip with color.
- param int color:
unpremultiplied ARGB
clear(self: skia.Canvas, color: skia.Color4f) -> None
Fills clip with color color using
BlendMode.kSrc
.This has the effect of replacing all pixels contained by clip with color.
- param color:
Color4f
representing unpremultiplied color.
- Canvas.clipPath(*args, **kwargs)
Overloaded function.
clipPath(self: skia.Canvas, path: skia.Path, op: skia.ClipOp, doAntiAlias: bool) -> None
Replaces clip with the intersection or difference of clip and path, with an aliased or anti-aliased clip edge.
Path.FillType
determines if path describes the area inside or outside its contours; and if path contour overlaps itself or another path contour, whether the overlaps form part of the area. path is transformed byMatrix
before it is combined with clip.clipPath(self: skia.Canvas, path: skia.Path, op: skia.ClipOp) -> None
Replaces clip with the intersection or difference of clip and path.
Resulting clip is aliased; pixels are fully contained by the clip.
Path.FillType
determines if path describes the area inside or outside its contours; and if path contour overlaps itself or another path contour, whether the overlaps form part of the area. path is transformed byMatrix
before it is combined with clip.clipPath(self: skia.Canvas, path: skia.Path, doAntiAlias: bool = False) -> None
Replaces clip with the intersection of clip and path.
Resulting clip is aliased; pixels are fully contained by the clip.
Path.FillType
determines if path describes the area inside or outside its contours; and if path contour overlaps itself or another path contour, whether the overlaps form part of the area. path is transformed byMatrix
before it is combined with clip.- path:
Path
to combine with clip- doAntiAlias:
true if clip is to be anti-aliased
- Canvas.clipRRect(*args, **kwargs)
Overloaded function.
clipRRect(self: skia.Canvas, rrect: skia.RRect, op: skia.ClipOp, doAntiAlias: bool) -> None
clipRRect(self: skia.Canvas, rrect: skia.RRect, op: skia.ClipOp) -> None
clipRRect(self: skia.Canvas, rrect: skia.RRect, doAntiAlias: bool = False) -> None
- Canvas.clipRect(*args, **kwargs)
Overloaded function.
clipRect(self: skia.Canvas, rect: skia.Rect, op: skia.ClipOp, doAntiAlias: bool) -> None
clipRect(self: skia.Canvas, rect: skia.Rect, op: skia.ClipOp) -> None
clipRect(self: skia.Canvas, rect: skia.Rect, doAntiAlias: bool = False) -> None
- Canvas.clipRegion(self: skia.Canvas, deviceRgn: skia.Region, op: skia.ClipOp = skia.ClipOp.kIntersect) None
Replaces clip with the intersection or difference of clip and
Region
deviceRgn.Resulting clip is aliased; pixels are fully contained by the clip. deviceRgn is unaffected by
Matrix
.- Parameters:
deviceRgn (skia.Region) –
Region
to combine with clipop (skia.ClipOp) –
ClipOp
to apply to clip
- Canvas.concat(*args, **kwargs)
Overloaded function.
concat(self: skia.Canvas, matrix: skia.Matrix) -> None
concat(self: skia.Canvas, m44: skia.M44) -> None
- Canvas.discard(self: skia.Canvas) None
Makes
Canvas
contents undefined.Subsequent calls that read
Canvas
pixels, such as drawing withBlendMode
, return undefined results.discard()
does not change clip orMatrix
.discard()
may do nothing, depending on the implementation ofSurface
orBaseDevice
that createdCanvas
.discard()
allows optimized performance on subsequent draws by removing cached data associated withSurface
orBaseDevice
. It is not necessary to calldiscard()
once done with SkCanvas; any cached data is deleted when owningSurface
orBaseDevice
is deleted.
- Canvas.drawAnnotation(self: skia.Canvas, rect: skia.Rect, key: str, value: skia.Data) None
Associates
Rect
onCanvas
when an annotation; a key-value pair, where the key is an UTF-8 string, and optional value is stored asData
.Only some canvas implementations, such as recording to
Picture
, or drawing to document PDF, use annotations.
- Canvas.drawArc(self: skia.Canvas, oval: skia.Rect, startAngle: float, sweepAngle: float, useCenter: bool, paint: skia.Paint) None
Draws arc using clip,
Matrix
, andPaint
paint.Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus sweepAngle. startAngle and sweepAngle are in degrees.
startAngle of zero places start point at the right middle edge of oval. A positive sweepAngle places arc end point clockwise from start point; a negative sweepAngle places arc end point counterclockwise from start point. sweepAngle may exceed 360 degrees, a full circle. If useCenter is true, draw a wedge that includes lines from oval center to arc end points. If useCenter is false, draw arc between end points.
If
Rect
oval is empty or sweepAngle is zero, nothing is drawn.- Parameters:
oval (skia.Rect) –
Rect
bounds of oval containing arc to drawstartAngle (float) – angle in degrees where arc begins
sweepAngle (float) – sweep angle in degrees; positive is clockwise
useCenter (bool) – if true, include the center of the oval
paint (skia.Paint) –
Paint
stroke or fill, blend, color, and so on, used to draw
- Canvas.drawAtlas(self: skia.Canvas, atlas: skia.Image, xform: list[skia.RSXform], tex: list[skia.Rect], colors: list[int], mode: skia.BlendMode, options: skia.SamplingOptions = skia.SamplingOptions(), cullRect: skia.Rect = None, paint: skia.Paint = None) None
Draws a set of sprites from atlas, using clip,
Matrix
, and optionalPaint
paint.paint uses anti-alias, alpha,
ColorFilter
,ImageFilter
, andBlendMode
to draw, if present. For each entry in the array,Rect
tex locates sprite in atlas, andRSXform
xform transforms it into destination space.xform, text, and colors if present, must contain count entries. Optional colors are applied for each sprite using
BlendMode
mode, treating sprite as source and colors as destination. Optional cullRect is a conservative bounds of all transformed sprites. If cullRect is outside of clip, canvas can skip drawing.If atlas is None, this draws nothing.
- Parameters:
atlas (skia.Image) –
Image
containing spritesxform (List[skia.RSXform]) –
RSXform
mappings for sprites in atlascolors (List[int]) – one per sprite, blended with sprite using
BlendMode
; may be Nonemode (skia.BlendMode) –
BlendMode
combining colors and spritescullRect (Union[skia.Rect,None]) – bounds of transformed sprites for efficient clipping; may be None
paint (Union[skia.Paint,None]) –
ColorFilter
,ImageFilter
,BlendMode
, and so on; may be None
- Canvas.drawBitmap(self: skia.Canvas, bitmap: skia.Bitmap, left: float, top: float, paint: skia.Paint = None) None
Draws
Bitmap
bitmap, with its top-left corner at (left, top), using clip,Matrix
, and optionalPaint
paint.If
Paint
paint is not nullptr, applyColorFilter
, alpha,ImageFilter
,BlendMode
, andDrawLooper
. If bitmap isColorType.kAlpha_8_ColorType
, applyShader
. If paint containsMaskFilter
, generate mask from bitmap bounds.If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as
Shader
made fromShader.MakeBitmapShader()
withTileMode.kClamp
set replicates the bitmap edge color when it samples outside of its bounds.- Parameters:
bitmap (skia.Bitmap) –
Bitmap
containing pixels, dimensions, and formatleft – left side of bitmap
top – top side of bitmap
paint –
Paint
containingBlendMode
,ColorFilter
,ImageFilter
, and so on; or nullptr
- Canvas.drawBitmapRect(*args, **kwargs)
Overloaded function.
drawBitmapRect(self: skia.Canvas, bitmap: skia.Bitmap, src: skia.Rect, dst: skia.Rect, paint: skia.Paint = None, constraint: skia.Canvas.SrcRectConstraint = skia.Canvas.SrcRectConstraint.kStrict_SrcRectConstraint) -> None
Draws
Rect
src ofBitmap
bitmap, scaled and translated to fillRect
dst.Additionally transform draw using clip,
Matrix
, and optionalPaint
paint.If
Paint
paint is supplied, applyColorFilter
, alpha,ImageFilter
,BlendMode
, andDrawLooper
. If bitmap isColorType.kAlpha_8_ColorType
, applyShader
. If paint containsMaskFilter
, generate mask from bitmap bounds.If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as
Shader
made fromShader.MakeBitmapShader()
withTileMode.kClamp
set replicates the bitmap edge color when it samples outside of its bounds.constraint set to
kStrict_SrcRectConstraint
limitsPaint
FilterQuality
to sample within src; set tokFast_SrcRectConstraint
allows sampling outside to improve performance.- bitmap:
Bitmap
containing pixels, dimensions, and format- src:
source
Rect
of image to draw from- dst:
destination
Rect
of image to draw to- paint:
Paint
containingBlendMode
,ColorFilter
,ImageFilter
, and so on; or nullptr- constraint:
filter strictly within src or draw faster
drawBitmapRect(self: skia.Canvas, bitmap: skia.Bitmap, isrc: skia.Rect, dst: skia.Rect, paint: skia.Paint = None, constraint: skia.Canvas.SrcRectConstraint = skia.Canvas.SrcRectConstraint.kStrict_SrcRectConstraint) -> None
Draws
IRect
isrc ofBitmap
bitmap, scaled and translated to fillRect
dst.Additionally transform draw using clip,
Matrix
, and optionalPaint
paint.If
Paint
paint is supplied, applyColorFilter
, alpha,ImageFilter
,BlendMode
, andDrawLooper
. If bitmap isColorType.kAlpha_8_ColorType
, applyShader
. If paint containsMaskFilter
, generate mask from bitmap bounds.If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as
Shader
made fromShader.MakeBitmapShader()
withTileMode.kClamp
set replicates the bitmap edge color when it samples outside of its bounds.constraint set to
kStrict_SrcRectConstraint
limitsPaint
FilterQuality
to sample within isrc; set tokFast_SrcRectConstraint
allows sampling outside to improve performance.- bitmap:
Bitmap
containing pixels, dimensions, and format- isrc:
source
IRect
of image to draw from- dst:
destination
Rect
of image to draw to- paint:
Paint
containingBlendMode
,ColorFilter
,ImageFilter
, and so on; or nullptr- constraint:
filter strictly within isrc or draw faster
drawBitmapRect(self: skia.Canvas, bitmap: skia.Bitmap, dst: skia.Rect, paint: skia.Paint = None, constraint: skia.Canvas.SrcRectConstraint = skia.Canvas.SrcRectConstraint.kStrict_SrcRectConstraint) -> None
Draws
Bitmap
bitmap, scaled and translated to fillRect
dst.bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries. Additionally transform draw using clip,
Matrix
, and optionalPaint
paint.If
Paint
paint is supplied, applyColorFilter
, alpha,ImageFilter
,BlendMode
, andDrawLooper
. If bitmap isColorType.kAlpha_8_ColorType
, applyShader
. If paint containsMaskFilter
, generate mask from bitmap bounds.If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, just as
Shader
made fromShader.MakeBitmapShader()
withTileMode.kClamp
set replicates the bitmap edge color when it samples outside of its bounds.constraint set to
kStrict_SrcRectConstraint
limitsPaint
FilterQuality
to sample within isrc; set tokFast_SrcRectConstraint
allows sampling outside to improve performance.- bitmap:
Bitmap
containing pixels, dimensions, and format- dst:
destination
Rect
of image to draw to- paint:
Paint
containingBlendMode
,ColorFilter
,ImageFilter
, and so on; or nullptr- constraint:
filter strictly within bitmap or draw faster
- Canvas.drawCircle(*args, **kwargs)
Overloaded function.
drawCircle(self: skia.Canvas, cx: float, cy: float, radius: float, paint: skia.Paint) -> None
Draws circle at (cx, cy) with radius using clip,
Matrix
, andPaint
paint.If radius is zero or less, nothing is drawn. In paint:
Paint.Style
determines if circle is stroked or filled; if stroked,Paint
stroke width describes the line thickness.- cx:
circle center on the x-axis
- cy:
circle center on the y-axis
- radius:
half the diameter of circle
- paint:
Paint
stroke or fill, blend, color, and so on, used to draw
drawCircle(self: skia.Canvas, center: skia.Point, radius: float, paint: skia.Paint) -> None
Draws circle at center with radius using clip,
Matrix
, andPaint
paint.If radius is zero or less, nothing is drawn. In paint:
Paint.Style
determines if circle is stroked or filled; if stroked,Paint
stroke width describes the line thickness.- center:
circle center
- radius:
half the diameter of circle
- paint:
Paint
stroke or fill, blend, color, and so on, used to draw
- Canvas.drawColor(*args, **kwargs)
Overloaded function.
drawColor(self: skia.Canvas, color: int, mode: skia.BlendMode = skia.BlendMode.kSrcOver) -> None
Fills clip with color color.
mode determines how ARGB is combined with destination.
- param int color:
unpremultiplied ARGB
- param skia.BlendMode mode:
BlendMode
used to combine source color and destination
drawColor(self: skia.Canvas, color: skia.Color4f, mode: skia.BlendMode = skia.BlendMode.kSrcOver) -> None
- Canvas.drawDRRect(self: skia.Canvas, outer: skia.RRect, inner: skia.RRect, paint: skia.Paint) None
Draws
RRect
outer and inner using clip,Matrix
, andPaint
paint.outer must contain inner or the drawing is undefined. In paint:
Paint.Style
determines ifRRect
is stroked or filled; if stroked,Paint
stroke width describes the line thickness, andPaint.Join
draws the corners rounded or square.GPU-backed platforms optimize drawing when both outer and inner are concave and outer contains inner. These platforms may not be able to draw
Path
built with identical data as fast.- Parameters:
outer (skia.RRect) –
RRect
outer bounds to drawinner (skia.RRect) –
RRect
inner bounds to drawpaint (skia.Paint) – stroke or fill, blend, color, and so on, used to draw
- Canvas.drawIRect(self: skia.Canvas, rect: skia.IRect, paint: skia.Paint) None
Draws
IRect
rect using clip,Matrix
, andPaint
paint.In paint:
Paint.Style
determines if rectangle is stroked or filled; if stroked,Paint
stroke width describes the line thickness, andPaint.Join
draws the corners rounded or square.- Parameters:
rect (skia.IRect) – rectangle to draw
paint (skia.Paint) – stroke or fill, blend, color, and so on, used to draw
- Canvas.drawImage(self: skia.Canvas, image: skia.Image, left: float, top: float, options: skia.SamplingOptions = skia.SamplingOptions(), paint: skia.Paint = None) None
Draws
Image
image, with its top-left corner at (left, top), using clip,Matrix
, and optionalPaint
paint.This is equivalent to drawImageRect() using a dst rect at (x,y) with the same width and height of the image.
- Image:
uncompressed rectangular map of pixels
- Left:
left side of image
- Top:
top side of image
- Paint:
Paint
containingBlendMode
,ColorFilter
,ImageFilter
, and so on; or nullptr
- Canvas.drawImageRect(*args, **kwargs)
Overloaded function.
drawImageRect(self: skia.Canvas, image: skia.Image, src: skia.Rect, dst: skia.Rect, options: skia.SamplingOptions = skia.SamplingOptions(), paint: skia.Paint = None, constraint: skia.Canvas.SrcRectConstraint = skia.Canvas.SrcRectConstraint.kStrict_SrcRectConstraint) -> None
Draws
Rect
src ofImage
image, scaled and translated to fillRect
dst.Additionally transform draw using clip,
Matrix
, and optionalPaint
paint.If
Paint
paint is supplied, applyColorFilter
, alpha,ImageFilter
,BlendMode
, andDrawLooper
. If image isColorType.kAlpha_8_ColorType
, applyShader
. If paint containsMaskFilter
, generate mask from image bounds.If generated mask extends beyond image bounds, replicate image edge colors, just as
Shader
made fromImage.makeShader()
withTileMode.kClamp
set replicates the image edge color when it samples outside of its bounds.When using a shader or shader mask filter, its coordinate system is based on the current CTM, so will reflect the dst rect geometry and is equivalent to drawRect(dst). The src rect is only used to access the provided image.
constraint set to
kStrict_SrcRectConstraint
limitsPaint
FilterQuality
to sample within src; set tokFast_SrcRectConstraint
allows sampling outside to improve performance.- image:
Image
containing pixels, dimensions, and format- src:
source
Rect
of image to draw from- dst:
destination
Rect
of image to draw to- paint:
Paint
containingBlendMode
,ColorFilter
,ImageFilter
, and so on; or nullptr- constraint:
filter strictly within src or draw faster
drawImageRect(self: skia.Canvas, image: skia.Image, isrc: skia.Rect, dst: skia.Rect, options: skia.SamplingOptions = skia.SamplingOptions(), paint: skia.Paint = None, constraint: skia.Canvas.SrcRectConstraint = skia.Canvas.SrcRectConstraint.kStrict_SrcRectConstraint) -> None
Draws
IRect
isrc ofImage
image, scaled and translated to fillRect
dst.Additionally transform draw using clip,
Matrix
, and optionalPaint
paint.If
Paint
paint is supplied, applyColorFilter
, alpha,ImageFilter
,BlendMode
, andDrawLooper
. If image isColorType.kAlpha_8_ColorType
, applyShader
. If paint containsMaskFilter
, generate mask from image bounds.If generated mask extends beyond image bounds, replicate image edge colors, just as
Shader
made fromImage.makeShader()
withTileMode.kClamp
set replicates the image edge color when it samples outside of its bounds.When using a shader or shader mask filter, its coordinate system is based on the current CTM, so will reflect the dst rect geometry and is equivalent to drawRect(dst). The isrc rect is only used to access the provided image.
constraint set to
kStrict_SrcRectConstraint
limitsPaint
FilterQuality
to sample within isrc; set tokFast_SrcRectConstraint
allows sampling outside to improve performance.- image:
Image
containing pixels, dimensions, and format- isrc:
source
IRect
of image to draw from- dst:
destination
Rect
of image to draw to- paint:
Paint
containingBlendMode
,ColorFilter
,ImageFilter
, and so on; or nullptr- constraint:
filter strictly within isrc or draw faster
drawImageRect(self: skia.Canvas, image: skia.Image, dst: skia.Rect, options: skia.SamplingOptions = skia.SamplingOptions(), paint: skia.Paint = None) -> None
Draws
Image
image, scaled and translated to fillRect
dst, using clip,Matrix
, and optionalPaint
paint.If
Paint
paint is supplied, applyColorFilter
, alpha,ImageFilter
,BlendMode
, andDrawLooper
. If image isColorType.kAlpha_8_ColorType
, applyShader
. If paint containsMaskFilter
, generate mask from image bounds.If generated mask extends beyond image bounds, replicate image edge colors, just as
Shader
made fromImage.makeShader()
withTileMode.kClamp
set replicates the image edge color when it samples outside of its bounds.When using a shader or shader mask filter, its coordinate system is based on the current CTM, so will reflect the dst rect geometry and is equivalent to drawRect(dst).
- image:
Image
containing pixels, dimensions, and format- dst:
destination
Rect
of image to draw to- paint:
Paint
containingBlendMode
,ColorFilter
,ImageFilter
, and so on; or nullptr- constraint:
filter strictly within src or draw faster
- Canvas.drawLine(*args, **kwargs)
Overloaded function.
drawLine(self: skia.Canvas, x0: float, y0: float, x1: float, y1: float, paint: skia.Paint) -> None
Draws line segment from (x0, y0) to (x1, y1) using clip,
Matrix
, andPaint
paint.In paint:
Paint
stroke width describes the line thickness;Paint.Cap
draws the end rounded or square;Paint.Style
is ignored, as if were set toPaint.Style.kStroke
.- x0:
start of line segment on x-axis
- y0:
start of line segment on y-axis
- x1:
end of line segment on x-axis
- y1:
end of line segment on y-axis
- paint:
stroke, blend, color, and so on, used to draw
drawLine(self: skia.Canvas, p0: skia.Point, p1: skia.Point, paint: skia.Paint) -> None
Draws line segment from p0 to p1 using clip,
Matrix
, andPaint
paint.In paint:
Paint
stroke width describes the line thickness;Paint.Cap
draws the end rounded or square;Paint.Style
is ignored, as if were set toPaint.Style.kStroke
.- p0:
start of line segment
- p1:
end of line segment
- paint:
stroke, blend, color, and so on, used to draw
- Canvas.drawOval(self: skia.Canvas, oval: skia.Rect, paint: skia.Paint) None
Draws oval using clip,
Matrix
, andPaint
paint.In paint:
Paint.Style
determines if oval is stroked or filled; if stroked,Paint
stroke width describes the line thickness, andPaint.Join
draws the corners rounded or square.- Parameters:
oval (skia.Rect) – oval to draw
paint (skia.Paint) – stroke or fill, blend, color, and so on, used to draw
- Canvas.drawPaint(self: skia.Canvas, paint: skia.Paint) None
Fills clip with
Paint
paint.Paint
componentsMaskFilter
,Shader
,ColorFilter
,ImageFilter
, andBlendMode
affect drawing;PathEffect
in paint is ignored.- Parameters:
paint (skia.Paint) – graphics state used to fill
Canvas
- Canvas.drawPatch(self: skia.Canvas, cubics: list[skia.Point], colors: list[int], texCoords: list[skia.Point], mode: skia.BlendMode, paint: skia.Paint) None
Draws a Coons patch: the interpolation of four cubics with shared corners, associating a color, and optionally a texture
Point
, with each corner.Coons patch uses clip and
Matrix
, paintShader
,ColorFilter
, alpha,ImageFilter
, andBlendMode
. IfShader
is provided it is treated as Coons patch texture;BlendMode
mode combines color colors andShader
if both are provided.Point
array cubics specifies fourPath
cubic starting at the top-left corner, in clockwise order, sharing every fourth point. The lastPath
cubic ends at the first point.Color array color associates colors with corners in top-left, top-right, bottom-right, bottom-left order.
If paint contains
Shader
,Point
array texCoords mapsShader
as texture to corners in top-left, top-right, bottom-right, bottom-left order. If texCoords is nullptr,Shader
is mapped using positions (derived from cubics).- Parameters:
cubics (List[skia.Point]) –
Path
cubic array, sharing common points (length 12)colors (List[int]) – color array, one for each corner (length 4)
texCoords (List[skia.Point]) –
Point
array of texture coordinates, mappingShader
to corners (length 4); may be an empty listmode –
BlendMode
for colors, and forShader
if paint has onepaint –
Shader
,ColorFilter
,BlendMode
, used to draw
- Canvas.drawPath(self: skia.Canvas, path: skia.Path, paint: skia.Paint) None
Draws
Path
path using clip,Matrix
, andPaint
paint.Path
contains an array of path contour, each of which may be open or closed.In paint:
Paint.Style
determines ifRRect
is stroked or filled: if filled,Path.FillType
determines whether path contour describes inside or outside of fill; if stroked,Paint
stroke width describes the line thickness,Paint
::Cap describes line ends, andPaint.Join
describes how corners are drawn.- Parameters:
paint (skia.Paint) – stroke, blend, color, and so on, used to draw
- Canvas.drawPicture(self: skia.Canvas, picture: skia.Picture, matrix: skia.Matrix = None, paint: skia.Paint = None) None
Draws
Picture
picture, using clip andMatrix
; transforming picture withMatrix
matrix, if provided; and usePaint
paint alpha,ColorFilter
,ImageFilter
, andBlendMode
, if provided.Picture
records a series of draw commands for later playback.matrix transformation is equivalent to: save(), concat(), drawPicture(), restore(). paint use is equivalent to: saveLayer(), drawPicture(), restore().
- Parameters:
picture (skia.Picture) – recorded drawing commands to play
matrix (skia.Matrix) –
Matrix
to rotate, scale, translate, and so on; may be Nonepaint (skia.Paint) –
Paint
to apply transparency, filtering, and so on; may be None
- Canvas.drawPoint(*args, **kwargs)
Overloaded function.
drawPoint(self: skia.Canvas, x: float, y: float, paint: skia.Paint) -> None
Draws point at (x, y) using clip,
Matrix
andPaint
paint.The shape of point drawn depends on paint
Paint.Cap
. If paint is set toPaint.Cap.kRound
, draw a circle of diameterPaint
stroke width. If paint is set toPaint.Cap.kSquare
orPaint.Cap.Butt
, draw a square of width and heightPaint
stroke width.Paint.Style
is ignored, as if were set toPaint.Style.kStroke
.- x:
left edge of circle or square
- y:
top edge of circle or square
- paint:
stroke, blend, color, and so on, used to draw
drawPoint(self: skia.Canvas, p: skia.Point, paint: skia.Paint) -> None
Draws point p using clip,
Matrix
andPaint
paint.The shape of point drawn depends on paint
Paint.Cap
. If paint is set toPaint.Cap.kRound
, draw a circle of diameterPaint
stroke width. If paint is set toPaint.Cap.kSquare
orPaint.Cap.Butt
, draw a square of width and heightPaint
stroke width.Paint.Style
is ignored, as if were set toPaint.Style.kStroke
.- p:
top-left edge of circle or square
- paint:
stroke, blend, color, and so on, used to draw
- Canvas.drawPoints(self: skia.Canvas, mode: skia.Canvas.PointMode, pts: list[skia.Point], paint: skia.Paint) None
Draws pts using clip,
Matrix
andPaint
paint.mode may be one of:
kPoints
,kLines
, orkPolygon
.If mode is
kPoints
, the shape of point drawn depends on paintPaint.Cap
. If paint is set toPaint.kRound
, each point draws a circle of diameterPaint
stroke width. If paint is set toPaint.kSquare
orPaint.kButt
, each point draws a square of width and heightPaint
stroke width.If mode is
kLines
, each pair of points draws a line segment. One line is drawn for every two points; each point is used once. If count is odd, the final point is ignored.If mode is
kPolygon
, each adjacent pair of points draws a line segment. count minus one lines are drawn; the first and last point are used once.Each line segment respects paint
Paint.Cap
andPaint
stroke width.Paint.Style
is ignored, as if were set toPaint.kStroke
.Always draws each element one at a time; is not affected by
Paint.Join
, and unlikedrawPath()
, does not create a mask from all points and lines before drawing.- Parameters:
mode (skia.Canvas.PointMode) – whether pts draws points or lines
pts (Iterable[skia.Point]) – array of points to draw
paint (skia.Paint) – stroke, blend, color, and so on, used to draw
- Canvas.drawRRect(self: skia.Canvas, rrect: skia.RRect, paint: skia.Paint) None
Draws
RRect
rrect using clip,Matrix
, andPaint
paint.In paint:
Paint.Style
determines if rrect is stroked or filled; if stroked,Paint
stroke width describes the line thickness, andPaint.Join
draws the corners rounded or square.rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or may have any combination of positive non-square radii for the four corners.
- Parameters:
rrect (skia.RRect) – rrect to draw
paint (skia.Paint) – stroke or fill, blend, color, and so on, used to draw
- Canvas.drawRect(self: skia.Canvas, rect: skia.Rect, paint: skia.Paint) None
Draws
Rect
rect using clip,Matrix
, andPaint
paint.In paint:
Paint.Style
determines if rectangle is stroked or filled; if stroked,Paint
stroke width describes the line thickness, andPaint.Join
draws the corners rounded or square.- Parameters:
rect (skia.Rect) – rectangle to draw
paint (skia.Paint) – stroke or fill, blend, color, and so on, used to draw
- Canvas.drawRegion(self: skia.Canvas, region: skia.Region, paint: skia.Paint) None
Draws
Region
region using clip,Matrix
, andPaint
paint.In paint:
Paint.Style
determines if rectangle is stroked or filled; if stroked,Paint
stroke width describes the line thickness, andPaint.Join
draws the corners rounded or square.- Parameters:
region (skia.Region) – region to draw
paint (skia.Paint) – stroke or fill, blend, color, and so on, used to draw
- Canvas.drawRoundRect(self: skia.Canvas, rect: skia.Rect, rx: float, ry: float, paint: skia.Paint) None
Draws
RRect
bounded byRect
rect, with corner radii (rx, ry) using clip,Matrix
, andPaint
paint.In paint:
Paint.Style
determines ifRRect
is stroked or filled; if stroked,Paint
stroke width describes the line thickness. If rx or ry are less than zero, they are treated as if they are zero. If rx plus ry exceeds rect width or rect height, radii are scaled down to fit. If rx and ry are zero,RRect
is drawn asRect
and if stroked is affected byPaint.Join
.- Parameters:
rect (skia.Rect) – SkRect bounds of SkRRect to draw
rx (float) – axis length on x-axis of oval describing rounded corners
ry (float) – axis length on y-axis of oval describing rounded corners
paint (skia.Paint) – stroke, blend, color, and so on, used to draw
- Canvas.drawSimpleText(self: skia.Canvas, text: str, x: float, y: float, font: skia.Font, paint: skia.Paint) None
Draws text, with origin at (x, y), using clip,
Matrix
,Font
font, andPaint
paint.This function uses the default character-to-glyph mapping from the
Typeface
in font. It does not perform typeface fallback for characters not found in theTypeface
. It does not perform kerning or other complex shaping; glyphs are positioned based on their default advances.Text size is affected by
Matrix
andFont
text size. Default text size is 12 point.All elements of paint:
PathEffect
,MaskFilter
,Shader
,ColorFilter
,ImageFilter
, andDrawLooper
; apply to text. By default, draws filled black glyphs.- Parameters:
text (str) – character code points or glyphs drawn
x (float) – start of text on x-axis
y (float) – start of text on y-axis
font (skia.Font) – typeface, text size and so, used to describe the text
paint (skia.Paint) – blend, color, and so on, used to draw
- Canvas.drawString(self: skia.Canvas, text: str, x: float, y: float, font: skia.Font, paint: skia.Paint) None
Draws string, with origin at (x, y), using clip,
Matrix
,Font
font, andPaint
paint.This function uses the default character-to-glyph mapping from the
Typeface
in font. It does not perform typeface fallback for characters not found in theTypeface
. It does not perform kerning; glyphs are positioned based on their default advances.String text is encoded as UTF-8.
Text size is affected by
Matrix
and font text size. Default text size is 12 point.All elements of paint:
PathEffect
,MaskFilter
,Shader
,ColorFilter
,ImageFilter
, andDrawLooper
; apply to text. By default, draws filled black glyphs.- Parameters:
text (str) – character code points drawn, ending with a char value of zero
x (float) – start of string on x-axis
y (float) – start of string on y-axis
font (skia.Font) – typeface, text size and so, used to describe the text
paint (skia.Paint) – blend, color, and so on, used to draw
- Canvas.drawTextBlob(self: skia.Canvas, blob: skia.TextBlob, x: float, y: float, paint: skia.Paint) None
Draws
TextBlob
blob at (x, y), using clip,Matrix
, andPaint
paint.blob contains glyphs, their positions, and paint attributes specific to text:
Typeface
,Paint
text size,Paint
text scale x,Paint
text skew x,Paint
::Align,Paint
::Hinting, anti-alias,Paint
fake bold,Paint
font embedded bitmaps,Paint
full hinting spacing, LCD text,Paint
linear text, andPaint
subpixel text.TextEncoding
must be set toTextEncoding.kGlyphID
.Elements of paint: anti-alias,
BlendMode
, color including alpha,ColorFilter
,Paint
dither,DrawLooper
,MaskFilter
,PathEffect
,Shader
, andPaint.Style
; apply to blob. IfPaint
containsPaint.kStroke
:Paint
iter limit,Paint.Cap
,Paint.Join
, andPaint
stroke width; apply toPath
created from blob.- Parameters:
blob (skia.TextBlob) – glyphs, positions, and their paints’ text size, typeface, and so on
x (float) – horizontal offset applied to blob
y (float) – vertical offset applied to blob
paint (skia.Paint) – blend, color, stroking, and so on, used to draw
- Canvas.drawVertices(self: skia.Canvas, vertices: skia.Vertices, paint: skia.Paint, mode: skia.BlendMode = skia.BlendMode.kModulate) None
Draws
Vertices
vertices, a triangle mesh, using clip andMatrix
. If paint contains anShader
and vertices does not contain texCoords, the shader is mapped using the vertices’ positions.If vvertices colors are defined in vertices, and
Paint
paint containsShader
,BlendMode
mode combines vertices colors withShader
.- Parameters:
vertices (skia.Vertices) – triangle mesh to draw
mode (skia.BlendMode) – combines vertices colors with
Shader
, if both are presentpaint (skia.Paint) – specifies the
Shader
, used asVertices
texture
- Canvas.flush(self: skia.Canvas) None
Triggers the immediate execution of all pending draw operations.
If
Canvas
is associated with GPU surface, resolves all pending GPU operations. IfCanvas
is associated with raster surface, has no effect; raster draw operations are never deferred.
- Canvas.getBaseLayerSize(self: skia.Canvas) skia.ISize
Gets the size of the base or root layer in global canvas coordinates.
The origin of the base layer is always (0,0). The area available for drawing may be smaller (due to clipping or saveLayer).
- Returns:
integral width and height of base layer
- Return type:
- Canvas.getDeviceClipBounds(*args, **kwargs)
Overloaded function.
getDeviceClipBounds(self: skia.Canvas) -> skia.IRect
Returns
IRect
bounds of clip, unaffected byMatrix
.If clip is empty, return
Rect.MakeEmpty()
, where allRect
sides equal zero.Unlike
getLocalClipBounds()
, returnedIRect
is not outset.- return:
bounds of clip in
BaseDevice
coordinates
getDeviceClipBounds(self: skia.Canvas, bounds: skia.IRect) -> bool
Returns
IRect
bounds of clip, unaffected byMatrix
.If clip is empty, return false, and set bounds to
Rect.MakeEmpty()
, where allRect
sides equal zero.Unlike
getLocalClipBounds()
, returnedIRect
is not outset.- param skia.Rect bounds:
Rect
of clip in device coordinates- return:
bounds of clip in
BaseDevice
coordinates
- Canvas.getLocalClipBounds(*args, **kwargs)
Overloaded function.
getLocalClipBounds(self: skia.Canvas) -> skia.Rect
Returns bounds of clip, transformed by inverse of
Matrix
.If clip is empty, return
Rect.MakeEmpty()
, where allRect
sides equal zero.Rect
returned is outset by one to account for partial pixel coverage if clip is anti-aliased.- return:
bounds of clip in local coordinates
getLocalClipBounds(self: skia.Canvas, bounds: skia.Rect) -> bool
Returns bounds of clip, transformed by inverse of
Matrix
.If clip is empty, return false, and set bounds to
Rect.MakeEmpty()
, where allRect
sides equal zero.bounds is outset by one to account for partial pixel coverage if clip is anti-aliased.
- bounds:
Rect
of clip in local coordinates- return:
true if clip bounds is not empty
- Canvas.getLocalToDevice(self: skia.Canvas) skia.M44
- Canvas.getProps(self: skia.Canvas, props: SkSurfaceProps) bool
Copies
SurfaceProps
, ifCanvas
is associated with raster surface or GPU surface, and returns true.Otherwise, returns false and leave props unchanged.
- Parameters:
props (skia.SurfaceProps) – storage for writable SurfaceProps
- Returns:
true if
SurfaceProps
was copied
- Canvas.getSaveCount(self: skia.Canvas) int
Returns the number of saved states, each containing:
Matrix
and clip.Equals the number of
save()
calls less the number ofrestore()
calls plus one. The save count of a new canvas is one.- Returns:
depth of save state stack
- Canvas.getSurface(self: skia.Canvas) SkSurface
Sometimes a canvas is owned by a surface.
If it is, getSurface() will return a bare pointer to that surface, else this will return nullptr.
- Return type:
skia.Surface or None
- Canvas.getTotalMatrix(self: skia.Canvas) skia.Matrix
Legacy version of
getLocalToDevice()
, which strips away any Z information, and just returns a 3x3 version.- Returns:
3x3 version of
getLocalToDevice()
- Canvas.imageInfo(self: skia.Canvas) skia.ImageInfo
-
If
Canvas
is not associated with raster surface or GPU surface, returnedColorType
is set toColorType.kUnknown_ColorType
.
- Canvas.isClipEmpty(self: skia.Canvas) bool
Returns true if clip is empty; that is, nothing will draw.
May do work when called; it should not be called more often than needed. However, once called, subsequent calls perform no work until clip changes.
- Returns:
true if clip is empty
- Canvas.isClipRect(self: skia.Canvas) bool
Returns true if clip is
Rect
and not empty.Returns false if the clip is empty, or if it is not
Rect
.- Returns:
true if clip is
Rect
and not empty
- Canvas.makeSurface(self: skia.Canvas, info: skia.ImageInfo, props: SkSurfaceProps = None) SkSurface
Creates
Surface
matching info and props, and associates it withCanvas
.Returns nullptr if no match found.
If props is nullptr, matches
SurfaceProps
inCanvas
. If props is nullptr andCanvas
does not haveSurfaceProps
, createsSurface
with defaultSurfaceProps
.- Parameters:
info (skia.ImageInfo) – width, height,
ColorType
,AlphaType
, andColorSpace
props (skia.SurfaceProps) –
SurfaceProps
to match; may be nullptr to matchCanvas
- Returns:
SkSurface matching info and props, or nullptr if no match is available
- Return type:
skia.Surface or None
- Canvas.peekPixels(self: skia.Canvas, pixmap: skia.Pixmap) bool
Returns true if
Canvas
has direct access to its pixels.Pixels are readable when
BaseDevice
is raster. Pixels are not readable whenCanvas
is returned from GPU surface, returned byDocument
::beginPage, returned byPictureRecorder
::beginRecording, orCanvas
is the base of a utility class like DebugCanvas.pixmap is valid only while
Canvas
is in scope and unchanged. AnyCanvas
orSurface
call may invalidate the pixmap values.- Parameters:
pixmap (skia.Pixmap) – storage for pixel state if pixels are readable; otherwise, ignored
- Returns:
true if
Canvas
has direct access to pixels
- Canvas.quickReject(*args, **kwargs)
Overloaded function.
quickReject(self: skia.Canvas, rect: skia.Rect) -> bool
quickReject(self: skia.Canvas, path: skia.Path) -> bool
Returns true if path, transformed by
Matrix
, can be quickly determined to be outside of clip.May return false even though path is outside of clip.
Use to check if an area to be drawn is clipped out, to skip subsequent draw calls.
- Canvas.readPixels(*args, **kwargs)
Overloaded function.
readPixels(self: skia.Canvas, dstInfo: skia.ImageInfo, dstPixels: Buffer, dstRowBytes: int = 0, srcX: int = 0, srcY: int = 0) -> bool
Copies
Rect
of pixels fromCanvas
into dstPixels.Matrix
and clip are ignored.Source
Rect
corners are (srcX, srcY) and ( imageInfo().width(), imageInfo().height()). DestinationRect
corners are (0, 0) and (array.shape[1], array.shape[0]). Copies each readable pixel intersecting both rectangles, without scaling, converting toColorType.kN32_ColorType
andAlphaType.kPremul_AlphaType
if required.Pixels are readable when
BaseDevice
is raster, or backed by a GPU. Pixels are not readable whenCanvas
is returned byDocument.beginPage()
, returned byPictureRecorder.beginRecording()
, orCanvas
is the base of a utility class like DebugCanvas.The destination pixel storage must be allocated by the caller.
Pixel values are converted only if
ColorType
andAlphaType
do not match. Only pixels within both source and destination rectangles are copied. array contents outsideRect
intersection are unchanged.Pass negative values for srcX or srcY to offset pixels across or down destination.
Does not copy, and returns false if:
Source and destination rectangles do not intersect.
Canvas
pixels could not be converted to
Canvas
pixels are not readable; for instance,Canvas
is document-based.
- dstInfo:
- dstPixels:
storage for pixels; dstInfo.height() times dstRowBytes, or larger
- dstRowBytes:
size of one destination row; dstInfo.width() times pixel size, or larger. Ignored when dstPixels has more than one-dimension.
- srcX:
offset into readable pixels on x-axis; may be negative
- srcY:
offset into readable pixels on y-axis; may be negative
- return:
true if pixels were copied
readPixels(self: skia.Canvas, pixmap: skia.Pixmap, srcX: int = 0, srcY: int = 0) -> bool
Copies
Rect
of pixels fromCanvas
into pixmap.Matrix
and clip are ignored.Source
Rect
corners are (srcX, srcY) and ( imageInfo().width(), imageInfo().height()). DestinationRect
corners are (0, 0) and (pixmap.width(), pixmap.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to pixmap.colorType() and pixmap.alphaType() if required.Pixels are readable when
BaseDevice
is raster, or backed by a GPU. Pixels are not readable whenCanvas
is returned byDocument.beginPage()
, returned byPictureRecorder.beginRecording()
, orCanvas
is the base of a utility class like DebugCanvas.Caller must allocate pixel storage in pixmap if needed.
Pixel values are converted only if
ColorType
andAlphaType
do not match. Only pixels within both source and destinationRect
are copied. pixmap pixels contents outsideRect
intersection are unchanged.Pass negative values for srcX or srcY to offset pixels across or down pixmap.
Does not copy, and returns false if:
Source and destination rectangles do not intersect.
Canvas
pixels could not be converted topixmap.colorType() or pixmap.alphaType().
Pixmap
pixels could not be allocated.pixmap.rowBytes() is too small to contain one row of pixels.
- pixmap:
storage for pixels copied from
Canvas
- srcX:
offset into readable pixels on x-axis; may be negative
- srcY:
offset into readable pixels on y-axis; may be negative
- return:
true if pixels were copied
readPixels(self: skia.Canvas, bitmap: skia.Bitmap, srcX: int = 0, srcY: int = 0) -> bool
Copies
Rect
of pixels fromCanvas
into bitmap.Matrix
and clip are ignored.Source
Rect
corners are (srcX, srcY) and ( imageInfo().width(), imageInfo().height()). DestinationRect
corners are (0, 0) and (bitmap.width(), bitmap.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to bitmap.colorType() and bitmap.alphaType() if required.Pixels are readable when
BaseDevice
is raster, or backed by a GPU. Pixels are not readable whenCanvas
is returned byDocument.beginPage()
, returned byPictureRecorder.beginRecording()
, orCanvas
is the base of a utility class like DebugCanvas.Caller must allocate pixel storage in bitmap if needed.
Bitmap
values are converted only ifColorType
andAlphaType
do not match. Only pixels within both source and destination rectangles are copied.Bitmap
pixels outsideRect
intersection are unchanged.Pass negative values for srcX or srcY to offset pixels across or down bitmap.
Does not copy, and returns false if:
Source and destination rectangles do not intersect.
Canvas
pixels could not be converted to bitmap.colorType()or bitmap.alphaType().
bitmap pixels could not be allocated.
bitmap.rowBytes() is too small to contain one row of pixels.
- bitmap:
storage for pixels copied from
Canvas
- srcX:
offset into readable pixels on x-axis; may be negative
- srcY:
offset into readable pixels on y-axis; may be negative
- return:
true if pixels were copied
- Canvas.resetMatrix(self: skia.Canvas) None
Sets SkMatrix to the identity matrix.
Any prior matrix state is overwritten.
- Canvas.restore(self: skia.Canvas) None
Removes changes to
Matrix
and clip sinceCanvas
state was last saved.The state is removed from the stack.
Does nothing if the stack is empty.
- Canvas.restoreToCount(self: skia.Canvas, saveCount: int) None
Restores state to
Matrix
and clip values whensave()
,saveLayer()
,saveLayerPreserveLCDTextRequests()
, orsaveLayerAlpha()
returned saveCount.Does nothing if saveCount is greater than state stack count. Restores state to initial values if saveCount is less than or equal to one.
- Parameters:
saveCount (int) – depth of state stack to restore
- Canvas.rotate(*args, **kwargs)
Overloaded function.
rotate(self: skia.Canvas, degrees: float) -> None
rotate(self: skia.Canvas, degrees: float, px: float, py: float) -> None
Rotates
Matrix
by degrees about a point at (px, py).Positive degrees rotates clockwise.
Mathematically, constructs a rotation matrix; premultiplies the rotation matrix by a translation matrix; then replaces
Matrix
with the resulting matrix premultiplied withMatrix
.This has the effect of rotating the drawing about a given point before transforming the result with
Matrix
.- degrees:
amount to rotate, in degrees
- px:
x-axis value of the point to rotate about
- py:
y-axis value of the point to rotate about
- Canvas.save(self: skia.Canvas) int
Saves
Matrix
and clip.Calling
restore()
discards changes toMatrix
and clip, restoring theMatrix
and clip to their state whensave()
was called.Matrix
may be changed bytranslate()
,scale()
,rotate()
,skew()
,concat()
,setMatrix()
, andresetMatrix()
. Clip may be changed byclipRect()
,clipRRect()
,clipPath()
,clipRegion()
.Saved
Canvas
state is put on a stack; multiple calls tosave()
should be balance by an equal number of calls torestore()
.Call
restoreToCount()
with result to restore this and subsequent saves.- Returns:
depth of saved stack
- Canvas.saveLayer(*args, **kwargs)
Overloaded function.
saveLayer(self: skia.Canvas, bounds: skia.Rect = None, paint: skia.Paint = None) -> int
Saves
Matrix
and clip, and allocates aBitmap
for subsequent drawing.Calling
restore()
discards changes toMatrix
and clip, and draws theBitmap
.Matrix
may be changed bytranslate()
,scale()
,rotate()
,skew()
,concat()
,setMatrix()
, andresetMatrix()
. Clip may be changed byclipRect()
,clipRRect()
,clipPath()
,clipRegion()
.Rect
bounds suggests but does not define theBitmap
size. To clip drawing to a specific rectangle, useclipRect()
.Optional
Paint
paint applies alpha,ColorFilter
,ImageFilter
, andBlendMode
whenrestore()
is called.Call
restoreToCount()
with returned value to restore this and subsequent saves.- bounds:
hint to limit the size of the layer; may be nullptr
- paint:
graphics state for layer; may be nullptr
- return:
depth of saved stack
saveLayer(self: skia.Canvas, layerRec: skia.Canvas.SaveLayerRec) -> int
Saves
Matrix
and clip, and allocates aBitmap
for subsequent drawing.Calling
restore()
discards changes toMatrix
and clip, and blendsBitmap
with alpha opacity onto the prior layer.Matrix
may be changed bytranslate()
,scale()
,rotate()
,skew()
,concat()
,setMatrix()
, andresetMatrix()
. Clip may be changed byclipRect()
,clipRRect()
,clipPath()
,clipRegion()
.SaveLayerRec
contains the state used to create the layer.Call
restoreToCount()
with returned value to restore this and subsequent saves.- layerRec:
layer state
- return:
depth of save state stack before this call was made.
- Canvas.saveLayerAlpha(self: skia.Canvas, bounds: skia.Rect, alpha: int) int
Saves
Matrix
and clip, and allocates aBitmap
for subsequent drawing.Calling
restore()
discards changes toMatrix
and clip, and blends layer with alpha opacity onto prior layer.Matrix
may be changed bytranslate()
,scale()
,rotate()
,skew()
,concat()
,setMatrix()
, andresetMatrix()
. Clip may be changed byclipRect()
,clipRRect()
,clipPath()
,clipRegion()
.Rect
bounds suggests but does not define theBitmap
size. To clip drawing to a specific rectangle, useclipRect()
.alpha of zero is fully transparent, 255 is fully opaque.
Call
restoreToCount()
with returned value to restore this and subsequent saves.- Parameters:
bounds (skia.Rect) – hint to limit the size of the layer; may be nullptr
alpha (int) – opacity of layer
- Returns:
depth of saved stack
- Canvas.scale(self: skia.Canvas, sx: float, sy: float) None
Scales
Matrix
by sx on the x-axis and sy on the y-axis.Mathematically, replaces
Matrix
with a scale matrix premultiplied withMatrix
.This has the effect of scaling the drawing by (sx, sy) before transforming the result with
Matrix
.- Parameters:
sx (float) – amount to scale on x-axis
sy (float) – amount to scale on y-axis
- Canvas.setMatrix(*args, **kwargs)
Overloaded function.
setMatrix(self: skia.Canvas, matrix: skia.M44) -> None
setMatrix(self: skia.Canvas, matrix: skia.Matrix) -> None
- Canvas.skew(self: skia.Canvas, sx: float, sy: float) None
Skews
Matrix
by sx on the x-axis and sy on the y-axis.A positive value of sx skews the drawing right as y-axis values increase; a positive value of sy skews the drawing down as x-axis values increase.
Mathematically, replaces
Matrix
with a skew matrix premultiplied withMatrix
.This has the effect of skewing the drawing by (sx, sy) before transforming the result with
Matrix
.- Parameters:
sx (float) – amount to skew on x-axis
sy (float) – amount to skew on y-axis
- Canvas.toarray(self: skia.Canvas, srcX: int = 0, srcY: int = 0, colorType: skia.ColorType = skia.ColorType.kUnknown_ColorType, alphaType: skia.AlphaType = skia.AlphaType.kUnpremul_AlphaType, colorSpace: skia.ColorSpace = None) numpy.ndarray
Exports a
numpy.ndarray
.- Parameters:
srcX – offset into readable pixels on x-axis; may be negative
srcY – offset into readable pixels on y-axis; may be negative
colorType – target
ColorType
alphaType – target
AlphaType
colorSpace – target
ColorSpace
- Returns:
numpy.ndarray
- Canvas.translate(self: skia.Canvas, dx: float, dy: float) None
Translates
Matrix
by dx along the x-axis and dy along the y-axis.Mathematically, replaces
Matrix
with a translation matrix premultiplied withMatrix
.This has the effect of moving the drawing by (dx, dy) before transforming the result with
Matrix
.- Parameters:
dx – distance to translate on x-axis
dy – distance to translate on y-axis
- Canvas.writePixels(*args, **kwargs)
Overloaded function.
writePixels(self: skia.Canvas, info: skia.ImageInfo, pixels: Buffer, rowBytes: int = 0, x: int = 0, y: int = 0) -> bool
Copies
Rect
from pixels toCanvas
.Matrix
and clip are ignored. SourceRect
corners are (0, 0) and (info.width(), info.height()). DestinationRect
corners are (x, y) and (imageInfo().width(), imageInfo().height()).Copies each readable pixel intersecting both rectangles, without scaling, converting to imageInfo().colorType() and imageInfo().alphaType() if required.
Pixels are writable when
BaseDevice
is raster, or backed by a GPU. Pixels are not writable whenCanvas
is returned byDocument.beginPage()
, returned byPictureRecorder.beginRecording()
, orCanvas
is the base of a utility class like DebugCanvas.Pixel values are converted only if
ColorType
andAlphaType
do not match. Only pixels within both source and destination rectangles are copied.Canvas
pixels outsideRect
intersection are unchanged.Pass negative values for x or y to offset pixels to the left or above
Canvas
pixels.Does not copy, and returns false if:
Source and destination rectangles do not intersect.
- pixels could not be converted to
Canvas
imageInfo().colorType() or imageInfo().alphaType().
- pixels could not be converted to
rowBytes is too small to contain one row of pixels.
writePixels(self: skia.Canvas, bitmap: skia.Bitmap, x: int = 0, y: int = 0) -> bool
Copies
Rect
from pixels toCanvas
.Matrix
and clip are ignored. SourceRect
corners are (0, 0) and (bitmap.width(), bitmap.height()).Destination
Rect
corners are (x, y) and (imageInfo().width(), imageInfo().height()).Copies each readable pixel intersecting both rectangles, without scaling, converting to imageInfo().colorType() and imageInfo().alphaType() if required.
Pixels are writable when
BaseDevice
is raster, or backed by a GPU. Pixels are not writable whenCanvas
is returned byDocument.beginPage()
, returned byPictureRecorder.beginRecording()
, orCanvas
is the base of a utility class like DebugCanvas.Pixel values are converted only if
ColorType
andAlphaType
do not match. Only pixels within both source and destination rectangles are copied.Canvas
pixels outsideRect
intersection are unchanged.Pass negative values for x or y to offset pixels to the left or above
Canvas
pixels.Does not copy, and returns false if:
Source and destination rectangles do not intersect.
bitmap does not have allocated pixels.
- bitmap pixels could not be converted to
Canvas.imageInfo()
.colorType() or alphaType().
bitmap pixels are inaccessible; for instance, bitmap wraps a texture.
Attributes
- Canvas.kAll_QuadAAFlags = <QuadAAFlags.kAll_QuadAAFlags: 15>
- Canvas.kBottom_QuadAAFlag = <QuadAAFlags.kBottom_QuadAAFlag: 8>
- Canvas.kF16ColorType = <SaveLayerFlags.kF16ColorType: 16>
- Canvas.kFast_SrcRectConstraint = <SrcRectConstraint.kFast_SrcRectConstraint: 1>
- Canvas.kInitWithPrevious_SaveLayerFlag = <SaveLayerFlags.kInitWithPrevious_SaveLayerFlag: 4>
- Canvas.kLeft_QuadAAFlag = <QuadAAFlags.kLeft_QuadAAFlag: 1>
- Canvas.kLines_PointMode = <PointMode.kLines_PointMode: 1>
- Canvas.kNone_QuadAAFlags = <QuadAAFlags.kNone_QuadAAFlags: 0>
- Canvas.kPoints_PointMode = <PointMode.kPoints_PointMode: 0>
- Canvas.kPolygon_PointMode = <PointMode.kPolygon_PointMode: 2>
- Canvas.kPreserveLCDText_SaveLayerFlag = <SaveLayerFlags.kPreserveLCDText_SaveLayerFlag: 2>
- Canvas.kRight_QuadAAFlag = <QuadAAFlags.kRight_QuadAAFlag: 4>
- Canvas.kStrict_SrcRectConstraint = <SrcRectConstraint.kStrict_SrcRectConstraint: 0>
- Canvas.kTop_QuadAAFlag = <QuadAAFlags.kTop_QuadAAFlag: 2>