Canvas
- class Canvas
Canvasprovides an interface for drawing, and how the drawing is clipped and transformed.Canvascontains a stack ofMatrixand clip values.CanvasandPainttogether provide the state to draw intoSurfaceorBaseDevice. EachCanvasdraw call transforms the geometry of the object by the concatenation of allMatrixvalues in the stack. The transformed geometry is clipped by the intersection of all of clip values in the stack. TheCanvasdraw calls usePaintto supply drawing state such as color,Typeface, text size, stroke width,Shaderand so on.To draw to a pixel-based destination, create raster surface or GPU surface. Request
CanvasfromSurfaceto obtain the interface to draw.Canvasgenerated by raster surface draws to memory visible to the CPU.Canvasgenerated by GPU surface uses Vulkan or OpenGL to draw to the GPU.To draw to a document, obtain
Canvasfrom SVG canvas, document PDF, orPictureRecorder.DocumentbasedCanvasand otherCanvassubclasses referenceBaseDevicedescribing the destination.Canvascan be constructed to draw toBitmapwithout first creating raster surface. This approach may be deprecated in the future.Classes
Canvas.LatticedividesBitmaporImageinto a rectangular grid.Members:
Members:
Members:
SaveLayerRec contains the state used to create the layer.
Members:
Methods
MakeRasterDirect(imageInfo: skia.ImageInfo, pixels: Buffer, rowBytes: int = 0, surfaceProps: SkSurfaceProps = None) -> skia.Canvas
MakeRasterDirectN32(width: int, height: int, pixels: Buffer, rowBytes: int = 0) -> skia.Canvas
accessTopLayerPixels(self: skia.Canvas, origin: skia.IPoint = None) -> object
androidFramework_setDeviceClipRestriction(self: skia.Canvas, rect: skia.IRect) -> None
clipRegion(self: skia.Canvas, deviceRgn: skia.Region, op: skia.ClipOp = skia.ClipOp.kIntersect) -> None
discard(self: skia.Canvas) -> None
drawAnnotation(self: skia.Canvas, rect: skia.Rect, key: str, value: skia.Data) -> None
drawArc(self: skia.Canvas, oval: skia.Rect, startAngle: float, sweepAngle: float, useCenter: bool, paint: skia.Paint) -> None
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
drawBitmap(self: skia.Canvas, bitmap: skia.Bitmap, left: float, top: float, paint: skia.Paint = None) -> None
drawDRRect(self: skia.Canvas, outer: skia.RRect, inner: skia.RRect, paint: skia.Paint) -> None
drawIRect(self: skia.Canvas, rect: skia.IRect, paint: skia.Paint) -> None
drawImage(self: skia.Canvas, image: skia.Image, left: float, top: float, options: skia.SamplingOptions = skia.SamplingOptions(), paint: skia.Paint = None) -> None
drawOval(self: skia.Canvas, oval: skia.Rect, paint: skia.Paint) -> None
drawPaint(self: skia.Canvas, paint: skia.Paint) -> None
drawPatch(self: skia.Canvas, cubics: list[skia.Point], colors: list[int], texCoords: list[skia.Point], mode: skia.BlendMode, paint: skia.Paint) -> None
drawPath(self: skia.Canvas, path: skia.Path, paint: skia.Paint) -> None
drawPicture(self: skia.Canvas, picture: skia.Picture, matrix: skia.Matrix = None, paint: skia.Paint = None) -> None
drawPoints(self: skia.Canvas, mode: skia.Canvas.PointMode, pts: list[skia.Point], paint: skia.Paint) -> None
drawRRect(self: skia.Canvas, rrect: skia.RRect, paint: skia.Paint) -> None
drawRect(self: skia.Canvas, rect: skia.Rect, paint: skia.Paint) -> None
drawRegion(self: skia.Canvas, region: skia.Region, paint: skia.Paint) -> None
drawRoundRect(self: skia.Canvas, rect: skia.Rect, rx: float, ry: float, paint: skia.Paint) -> None
drawSimpleText(self: skia.Canvas, text: str, x: float, y: float, font: skia.Font, paint: skia.Paint) -> None
drawString(self: skia.Canvas, text: str, x: float, y: float, font: skia.Font, paint: skia.Paint) -> None
drawTextBlob(self: skia.Canvas, blob: skia.TextBlob, x: float, y: float, paint: skia.Paint) -> None
drawTextOnPath(self: skia.Canvas, text: str, path: skia.Path, matrix: skia.Matrix, font: skia.Font, paint: skia.Paint) -> None
drawVertices(self: skia.Canvas, vertices: skia.Vertices, paint: skia.Paint, mode: skia.BlendMode = skia.BlendMode.kModulate) -> None
flush(self: skia.Canvas) -> None
getBaseLayerSize(self: skia.Canvas) -> skia.ISize
getLocalToDevice(self: skia.Canvas) -> skia.M44
getProps(self: skia.Canvas, props: SkSurfaceProps) -> bool
getSaveCount(self: skia.Canvas) -> int
getSurface(self: skia.Canvas) -> SkSurface
getTotalMatrix(self: skia.Canvas) -> skia.Matrix
imageInfo(self: skia.Canvas) -> skia.ImageInfo
isClipEmpty(self: skia.Canvas) -> bool
isClipRect(self: skia.Canvas) -> bool
makeSurface(self: skia.Canvas, info: skia.ImageInfo, props: SkSurfaceProps = None) -> SkSurface
peekPixels(self: skia.Canvas, pixmap: skia.Pixmap) -> bool
resetMatrix(self: skia.Canvas) -> None
restore(self: skia.Canvas) -> None
restoreToCount(self: skia.Canvas, saveCount: int) -> None
save(self: skia.Canvas) -> int
saveLayerAlpha(self: skia.Canvas, bounds: skia.Rect, alpha: int) -> int
scale(self: skia.Canvas, sx: float, sy: float) -> None
skew(self: skia.Canvas, sx: float, sy: float) -> None
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
translate(self: skia.Canvas, dx: float, dy: float) -> None
Attributes
Methods
- static Canvas.MakeRasterDirect(imageInfo: skia.ImageInfo, pixels: Buffer, rowBytes: int = 0, surfaceProps: SkSurfaceProps = None) skia.Canvas
Allocates raster
Canvasthat will draw directly into pixels.Canvasis returned if all parameters are valid. Valid parameters include: info dimensions are zero or positive; info containsColorTypeandAlphaTypesupported 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
Surfacerow 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
Canvasspecified by inline image specification.Subsequent
Canvascalls draw into pixels.ColorTypeis set toColorType.kN32_ColorType.AlphaTypeis set toAlphaType.kPremul_AlphaType. To access pixels after drawing, call flush() or peekPixels().Canvasis 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
Surfacerow to the next, or zero
- Canvas.__init__(*args, **kwargs)
Overloaded function.
__init__(self: skia.Canvas) -> None
Creates an empty
Canvaswith 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
Canvasbacked by numpy array.Subsequent
Canvascalls 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
Canvasof the specified dimensions without aSurface.Used by subclasses with custom implementations for draw member functions.
If props equals None,
SurfacePropsare created withSurfaceProps.InitTypesettings, 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
Canvasis in scope and unchanged. AnyCanvascall orSurfacecall may invalidate the returned address and other returned values.If pixels are inaccessible, returns None.
- Parameters:
origin – storage for
Canvastop 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:
Color4frepresenting 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.FillTypedetermines 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 byMatrixbefore 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.FillTypedetermines 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 byMatrixbefore 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.FillTypedetermines 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 byMatrixbefore it is combined with clip.- path:
Pathto 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
RegiondeviceRgn.Resulting clip is aliased; pixels are fully contained by the clip. deviceRgn is unaffected by
Matrix.- Parameters:
deviceRgn (skia.Region) –
Regionto combine with clipop (skia.ClipOp) –
ClipOpto 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
Canvascontents undefined.Subsequent calls that read
Canvaspixels, such as drawing withBlendMode, return undefined results.discard()does not change clip orMatrix.discard()may do nothing, depending on the implementation ofSurfaceorBaseDevicethat createdCanvas.discard()allows optimized performance on subsequent draws by removing cached data associated withSurfaceorBaseDevice. It is not necessary to calldiscard()once done with SkCanvas; any cached data is deleted when owningSurfaceorBaseDeviceis deleted.
- Canvas.drawAnnotation(self: skia.Canvas, rect: skia.Rect, key: str, value: skia.Data) None
Associates
RectonCanvaswhen 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, andPaintpaint.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
Rectoval is empty or sweepAngle is zero, nothing is drawn.- Parameters:
oval (skia.Rect) –
Rectbounds 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) –
Paintstroke 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 optionalPaintpaint.paint uses anti-alias, alpha,
ColorFilter,ImageFilter, andBlendModeto draw, if present. For each entry in the array,Recttex locates sprite in atlas, andRSXformxform transforms it into destination space.xform, text, and colors if present, must contain count entries. Optional colors are applied for each sprite using
BlendModemode, 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) –
Imagecontaining spritesxform (List[skia.RSXform]) –
RSXformmappings for sprites in atlascolors (List[int]) – one per sprite, blended with sprite using
BlendMode; may be Nonemode (skia.BlendMode) –
BlendModecombining 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
Bitmapbitmap, with its top-left corner at (left, top), using clip,Matrix, and optionalPaintpaint.If
Paintpaint 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
Shadermade fromShader.MakeBitmapShader()withTileMode.kClampset replicates the bitmap edge color when it samples outside of its bounds.- Parameters:
bitmap (skia.Bitmap) –
Bitmapcontaining pixels, dimensions, and formatleft – left side of bitmap
top – top side of bitmap
paint –
PaintcontainingBlendMode,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
Rectsrc ofBitmapbitmap, scaled and translated to fillRectdst.Additionally transform draw using clip,
Matrix, and optionalPaintpaint.If
Paintpaint 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
Shadermade fromShader.MakeBitmapShader()withTileMode.kClampset replicates the bitmap edge color when it samples outside of its bounds.constraint set to
kStrict_SrcRectConstraintlimitsPaintFilterQualityto sample within src; set tokFast_SrcRectConstraintallows sampling outside to improve performance.- bitmap:
Bitmapcontaining pixels, dimensions, and format- src:
source
Rectof image to draw from- dst:
destination
Rectof image to draw to- paint:
PaintcontainingBlendMode,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
IRectisrc ofBitmapbitmap, scaled and translated to fillRectdst.Additionally transform draw using clip,
Matrix, and optionalPaintpaint.If
Paintpaint 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
Shadermade fromShader.MakeBitmapShader()withTileMode.kClampset replicates the bitmap edge color when it samples outside of its bounds.constraint set to
kStrict_SrcRectConstraintlimitsPaintFilterQualityto sample within isrc; set tokFast_SrcRectConstraintallows sampling outside to improve performance.- bitmap:
Bitmapcontaining pixels, dimensions, and format- isrc:
source
IRectof image to draw from- dst:
destination
Rectof image to draw to- paint:
PaintcontainingBlendMode,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
Bitmapbitmap, scaled and translated to fillRectdst.bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries. Additionally transform draw using clip,
Matrix, and optionalPaintpaint.If
Paintpaint 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
Shadermade fromShader.MakeBitmapShader()withTileMode.kClampset replicates the bitmap edge color when it samples outside of its bounds.constraint set to
kStrict_SrcRectConstraintlimitsPaintFilterQualityto sample within isrc; set tokFast_SrcRectConstraintallows sampling outside to improve performance.- bitmap:
Bitmapcontaining pixels, dimensions, and format- dst:
destination
Rectof image to draw to- paint:
PaintcontainingBlendMode,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, andPaintpaint.If radius is zero or less, nothing is drawn. In paint:
Paint.Styledetermines if circle is stroked or filled; if stroked,Paintstroke 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:
Paintstroke 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, andPaintpaint.If radius is zero or less, nothing is drawn. In paint:
Paint.Styledetermines if circle is stroked or filled; if stroked,Paintstroke width describes the line thickness.- center:
circle center
- radius:
half the diameter of circle
- paint:
Paintstroke 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:
BlendModeused 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
RRectouter and inner using clip,Matrix, andPaintpaint.outer must contain inner or the drawing is undefined. In paint:
Paint.Styledetermines ifRRectis stroked or filled; if stroked,Paintstroke width describes the line thickness, andPaint.Joindraws 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
Pathbuilt with identical data as fast.- Parameters:
outer (skia.RRect) –
RRectouter bounds to drawinner (skia.RRect) –
RRectinner 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
IRectrect using clip,Matrix, andPaintpaint.In paint:
Paint.Styledetermines if rectangle is stroked or filled; if stroked,Paintstroke width describes the line thickness, andPaint.Joindraws 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
Imageimage, with its top-left corner at (left, top), using clip,Matrix, and optionalPaintpaint.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:
PaintcontainingBlendMode,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
Rectsrc ofImageimage, scaled and translated to fillRectdst.Additionally transform draw using clip,
Matrix, and optionalPaintpaint.If
Paintpaint 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
Shadermade fromImage.makeShader()withTileMode.kClampset 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_SrcRectConstraintlimitsPaintFilterQualityto sample within src; set tokFast_SrcRectConstraintallows sampling outside to improve performance.- image:
Imagecontaining pixels, dimensions, and format- src:
source
Rectof image to draw from- dst:
destination
Rectof image to draw to- paint:
PaintcontainingBlendMode,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
IRectisrc ofImageimage, scaled and translated to fillRectdst.Additionally transform draw using clip,
Matrix, and optionalPaintpaint.If
Paintpaint 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
Shadermade fromImage.makeShader()withTileMode.kClampset 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_SrcRectConstraintlimitsPaintFilterQualityto sample within isrc; set tokFast_SrcRectConstraintallows sampling outside to improve performance.- image:
Imagecontaining pixels, dimensions, and format- isrc:
source
IRectof image to draw from- dst:
destination
Rectof image to draw to- paint:
PaintcontainingBlendMode,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
Imageimage, scaled and translated to fillRectdst, using clip,Matrix, and optionalPaintpaint.If
Paintpaint 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
Shadermade fromImage.makeShader()withTileMode.kClampset 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:
Imagecontaining pixels, dimensions, and format- dst:
destination
Rectof image to draw to- paint:
PaintcontainingBlendMode,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, andPaintpaint.In paint:
Paintstroke width describes the line thickness;Paint.Capdraws the end rounded or square;Paint.Styleis 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, andPaintpaint.In paint:
Paintstroke width describes the line thickness;Paint.Capdraws the end rounded or square;Paint.Styleis 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, andPaintpaint.In paint:
Paint.Styledetermines if oval is stroked or filled; if stroked,Paintstroke width describes the line thickness, andPaint.Joindraws 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
Paintpaint.PaintcomponentsMaskFilter,Shader,ColorFilter,ImageFilter, andBlendModeaffect drawing;PathEffectin 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. IfShaderis provided it is treated as Coons patch texture;BlendModemode combines color colors andShaderif both are provided.Pointarray cubics specifies fourPathcubic starting at the top-left corner, in clockwise order, sharing every fourth point. The lastPathcubic 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,Pointarray texCoords mapsShaderas texture to corners in top-left, top-right, bottom-right, bottom-left order. If texCoords is nullptr,Shaderis mapped using positions (derived from cubics).- Parameters:
cubics (List[skia.Point]) –
Pathcubic array, sharing common points (length 12)colors (List[int]) – color array, one for each corner (length 4)
texCoords (List[skia.Point]) –
Pointarray of texture coordinates, mappingShaderto corners (length 4); may be an empty listmode –
BlendModefor colors, and forShaderif paint has onepaint –
Shader,ColorFilter,BlendMode, used to draw
- Canvas.drawPath(self: skia.Canvas, path: skia.Path, paint: skia.Paint) None
Draws
Pathpath using clip,Matrix, andPaintpaint.Pathcontains an array of path contour, each of which may be open or closed.In paint:
Paint.Styledetermines ifRRectis stroked or filled: if filled,Path.FillTypedetermines whether path contour describes inside or outside of fill; if stroked,Paintstroke width describes the line thickness,Paint::Cap describes line ends, andPaint.Joindescribes 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
Picturepicture, using clip andMatrix; transforming picture withMatrixmatrix, if provided; and usePaintpaint alpha,ColorFilter,ImageFilter, andBlendMode, if provided.Picturerecords 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) –
Matrixto rotate, scale, translate, and so on; may be Nonepaint (skia.Paint) –
Paintto 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,
MatrixandPaintpaint.The shape of point drawn depends on paint
Paint.Cap. If paint is set toPaint.Cap.kRound, draw a circle of diameterPaintstroke width. If paint is set toPaint.Cap.kSquareorPaint.Cap.Butt, draw a square of width and heightPaintstroke width.Paint.Styleis 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,
MatrixandPaintpaint.The shape of point drawn depends on paint
Paint.Cap. If paint is set toPaint.Cap.kRound, draw a circle of diameterPaintstroke width. If paint is set toPaint.Cap.kSquareorPaint.Cap.Butt, draw a square of width and heightPaintstroke width.Paint.Styleis 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,
MatrixandPaintpaint.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 diameterPaintstroke width. If paint is set toPaint.kSquareorPaint.kButt, each point draws a square of width and heightPaintstroke 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.CapandPaintstroke width.Paint.Styleis 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
RRectrrect using clip,Matrix, andPaintpaint.In paint:
Paint.Styledetermines if rrect is stroked or filled; if stroked,Paintstroke width describes the line thickness, andPaint.Joindraws 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
Rectrect using clip,Matrix, andPaintpaint.In paint:
Paint.Styledetermines if rectangle is stroked or filled; if stroked,Paintstroke width describes the line thickness, andPaint.Joindraws 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
Regionregion using clip,Matrix, andPaintpaint.In paint:
Paint.Styledetermines if rectangle is stroked or filled; if stroked,Paintstroke width describes the line thickness, andPaint.Joindraws 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
RRectbounded byRectrect, with corner radii (rx, ry) using clip,Matrix, andPaintpaint.In paint:
Paint.Styledetermines ifRRectis stroked or filled; if stroked,Paintstroke 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,RRectis drawn asRectand 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,Fontfont, andPaintpaint.This function uses the default character-to-glyph mapping from the
Typefacein 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
MatrixandFonttext 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,Fontfont, andPaintpaint.This function uses the default character-to-glyph mapping from the
Typefacein 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
Matrixand 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
TextBlobblob at (x, y), using clip,Matrix, andPaintpaint.blob contains glyphs, their positions, and paint attributes specific to text:
Typeface,Painttext size,Painttext scale x,Painttext skew x,Paint::Align,Paint::Hinting, anti-alias,Paintfake bold,Paintfont embedded bitmaps,Paintfull hinting spacing, LCD text,Paintlinear text, andPaintsubpixel text.TextEncodingmust be set toTextEncoding.kGlyphID.Elements of paint: anti-alias,
BlendMode, color including alpha,ColorFilter,Paintdither,DrawLooper,MaskFilter,PathEffect,Shader, andPaint.Style; apply to blob. IfPaintcontainsPaint.kStroke:Paintiter limit,Paint.Cap,Paint.Join, andPaintstroke width; apply toPathcreated 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.drawTextOnPath(self: skia.Canvas, text: str, path: skia.Path, matrix: skia.Matrix, font: skia.Font, paint: skia.Paint) None
- Canvas.drawVertices(self: skia.Canvas, vertices: skia.Vertices, paint: skia.Paint, mode: skia.BlendMode = skia.BlendMode.kModulate) None
Draws
Verticesvertices, a triangle mesh, using clip andMatrix. If paint contains anShaderand vertices does not contain texCoords, the shader is mapped using the vertices’ positions.If vvertices colors are defined in vertices, and
Paintpaint containsShader,BlendModemode 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 asVerticestexture
- Canvas.flush(self: skia.Canvas) None
Triggers the immediate execution of all pending draw operations.
If
Canvasis associated with GPU surface, resolves all pending GPU operations. IfCanvasis 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
IRectbounds of clip, unaffected byMatrix.If clip is empty, return
Rect.MakeEmpty(), where allRectsides equal zero.Unlike
getLocalClipBounds(), returnedIRectis not outset.- return:
bounds of clip in
BaseDevicecoordinates
getDeviceClipBounds(self: skia.Canvas, bounds: skia.IRect) -> bool
Returns
IRectbounds of clip, unaffected byMatrix.If clip is empty, return false, and set bounds to
Rect.MakeEmpty(), where allRectsides equal zero.Unlike
getLocalClipBounds(), returnedIRectis not outset.- param skia.Rect bounds:
Rectof clip in device coordinates- return:
bounds of clip in
BaseDevicecoordinates
- 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 allRectsides equal zero.Rectreturned 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 allRectsides equal zero.bounds is outset by one to account for partial pixel coverage if clip is anti-aliased.
- bounds:
Rectof 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, ifCanvasis 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
SurfacePropswas copied
- Canvas.getSaveCount(self: skia.Canvas) int
Returns the number of saved states, each containing:
Matrixand 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
Canvasis not associated with raster surface or GPU surface, returnedColorTypeis 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
Rectand not empty.Returns false if the clip is empty, or if it is not
Rect.- Returns:
true if clip is
Rectand not empty
- Canvas.makeSurface(self: skia.Canvas, info: skia.ImageInfo, props: SkSurfaceProps = None) SkSurface
Creates
Surfacematching info and props, and associates it withCanvas.Returns nullptr if no match found.
If props is nullptr, matches
SurfacePropsinCanvas. If props is nullptr andCanvasdoes not haveSurfaceProps, createsSurfacewith defaultSurfaceProps.- Parameters:
info (skia.ImageInfo) – width, height,
ColorType,AlphaType, andColorSpaceprops (skia.SurfaceProps) –
SurfacePropsto 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
Canvashas direct access to its pixels.Pixels are readable when
BaseDeviceis raster. Pixels are not readable whenCanvasis returned from GPU surface, returned byDocument::beginPage, returned byPictureRecorder::beginRecording, orCanvasis the base of a utility class like DebugCanvas.pixmap is valid only while
Canvasis in scope and unchanged. AnyCanvasorSurfacecall may invalidate the pixmap values.- Parameters:
pixmap (skia.Pixmap) – storage for pixel state if pixels are readable; otherwise, ignored
- Returns:
true if
Canvashas 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
Rectof pixels fromCanvasinto dstPixels.Matrixand clip are ignored.Source
Rectcorners are (srcX, srcY) and ( imageInfo().width(), imageInfo().height()). DestinationRectcorners are (0, 0) and (array.shape[1], array.shape[0]). Copies each readable pixel intersecting both rectangles, without scaling, converting toColorType.kN32_ColorTypeandAlphaType.kPremul_AlphaTypeif required.Pixels are readable when
BaseDeviceis raster, or backed by a GPU. Pixels are not readable whenCanvasis returned byDocument.beginPage(), returned byPictureRecorder.beginRecording(), orCanvasis the base of a utility class like DebugCanvas.The destination pixel storage must be allocated by the caller.
Pixel values are converted only if
ColorTypeandAlphaTypedo not match. Only pixels within both source and destination rectangles are copied. array contents outsideRectintersection 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.
Canvaspixels could not be converted to
Canvaspixels are not readable; for instance,Canvasis 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
Rectof pixels fromCanvasinto pixmap.Matrixand clip are ignored.Source
Rectcorners are (srcX, srcY) and ( imageInfo().width(), imageInfo().height()). DestinationRectcorners 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
BaseDeviceis raster, or backed by a GPU. Pixels are not readable whenCanvasis returned byDocument.beginPage(), returned byPictureRecorder.beginRecording(), orCanvasis the base of a utility class like DebugCanvas.Caller must allocate pixel storage in pixmap if needed.
Pixel values are converted only if
ColorTypeandAlphaTypedo not match. Only pixels within both source and destinationRectare copied. pixmap pixels contents outsideRectintersection 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.
Canvaspixels could not be converted topixmap.colorType() or pixmap.alphaType().
Pixmappixels 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
Rectof pixels fromCanvasinto bitmap.Matrixand clip are ignored.Source
Rectcorners are (srcX, srcY) and ( imageInfo().width(), imageInfo().height()). DestinationRectcorners 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
BaseDeviceis raster, or backed by a GPU. Pixels are not readable whenCanvasis returned byDocument.beginPage(), returned byPictureRecorder.beginRecording(), orCanvasis the base of a utility class like DebugCanvas.Caller must allocate pixel storage in bitmap if needed.
Bitmapvalues are converted only ifColorTypeandAlphaTypedo not match. Only pixels within both source and destination rectangles are copied.Bitmappixels outsideRectintersection 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.
Canvaspixels 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
Matrixand clip sinceCanvasstate 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
Matrixand 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
Matrixby 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
Matrixwith 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
Matrixand clip.Calling
restore()discards changes toMatrixand clip, restoring theMatrixand clip to their state whensave()was called.Matrixmay be changed bytranslate(),scale(),rotate(),skew(),concat(),setMatrix(), andresetMatrix(). Clip may be changed byclipRect(),clipRRect(),clipPath(),clipRegion().Saved
Canvasstate 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
Matrixand clip, and allocates aBitmapfor subsequent drawing.Calling
restore()discards changes toMatrixand clip, and draws theBitmap.Matrixmay be changed bytranslate(),scale(),rotate(),skew(),concat(),setMatrix(), andresetMatrix(). Clip may be changed byclipRect(),clipRRect(),clipPath(),clipRegion().Rectbounds suggests but does not define theBitmapsize. To clip drawing to a specific rectangle, useclipRect().Optional
Paintpaint applies alpha,ColorFilter,ImageFilter, andBlendModewhenrestore()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
Matrixand clip, and allocates aBitmapfor subsequent drawing.Calling
restore()discards changes toMatrixand clip, and blendsBitmapwith alpha opacity onto the prior layer.Matrixmay be changed bytranslate(),scale(),rotate(),skew(),concat(),setMatrix(), andresetMatrix(). Clip may be changed byclipRect(),clipRRect(),clipPath(),clipRegion().SaveLayerReccontains 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
Matrixand clip, and allocates aBitmapfor subsequent drawing.Calling
restore()discards changes toMatrixand clip, and blends layer with alpha opacity onto prior layer.Matrixmay be changed bytranslate(),scale(),rotate(),skew(),concat(),setMatrix(), andresetMatrix(). Clip may be changed byclipRect(),clipRRect(),clipPath(),clipRegion().Rectbounds suggests but does not define theBitmapsize. 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
Matrixby sx on the x-axis and sy on the y-axis.Mathematically, replaces
Matrixwith 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
Matrixby 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
Matrixwith 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
ColorTypealphaType – target
AlphaTypecolorSpace – target
ColorSpace
- Returns:
numpy.ndarray
- Canvas.translate(self: skia.Canvas, dx: float, dy: float) None
Translates
Matrixby dx along the x-axis and dy along the y-axis.Mathematically, replaces
Matrixwith 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
Rectfrom pixels toCanvas.Matrixand clip are ignored. SourceRectcorners are (0, 0) and (info.width(), info.height()). DestinationRectcorners 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
BaseDeviceis raster, or backed by a GPU. Pixels are not writable whenCanvasis returned byDocument.beginPage(), returned byPictureRecorder.beginRecording(), orCanvasis the base of a utility class like DebugCanvas.Pixel values are converted only if
ColorTypeandAlphaTypedo not match. Only pixels within both source and destination rectangles are copied.Canvaspixels outsideRectintersection are unchanged.Pass negative values for x or y to offset pixels to the left or above
Canvaspixels.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
Rectfrom pixels toCanvas.Matrixand clip are ignored. SourceRectcorners are (0, 0) and (bitmap.width(), bitmap.height()).Destination
Rectcorners 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
BaseDeviceis raster, or backed by a GPU. Pixels are not writable whenCanvasis returned byDocument.beginPage(), returned byPictureRecorder.beginRecording(), orCanvasis the base of a utility class like DebugCanvas.Pixel values are converted only if
ColorTypeandAlphaTypedo not match. Only pixels within both source and destination rectangles are copied.Canvaspixels outsideRectintersection are unchanged.Pass negative values for x or y to offset pixels to the left or above
Canvaspixels.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>