SourceModule skia
Python bindings for the Skia Graphics Library.
This module provides Python wrappers around Skia's C++ API, so that you can draw text, geometry, and images from Python on desktop and mobile platforms.
Overview§
Skia is organized around the Canvas object. It is the host for the "draw"
calls: draw_rect, draw_path, draw_text, etc. Each of these has two
components: the primitive being drawn (Rect, Path, etc.) and color/style
attributes (Paint).
canvas.draw_rect(rect, paint)
The paint holds much of the state describing how the rectangle (in this case) is drawn: what color it is, if it is filled or stroked, how it should blend with what was previously drawn.
The canvas holds relatively little state. It points to the actual pixels being drawn, and it maintains a stack of matrices and clips. Thus in the above call, the canvas' current matrix may transform the coordinates of the rectangle (translation, rotation, skewing, perspective), and the canvas' current clip may restrict where on the canvas the rectangle will be drawn, but all other stylistic attributes of the drawing are controlled by the paint.
Most Skia types are re-exported at the module root (for example Canvas, Surface,
Paint, Path, Image), so you can usually write skia.Canvas without digging
into the module tree.
Getting started§
A minimal example that draws into a raster surface and saves a PNG:
import skia
surface = skia.Surface(256, 256)
canvas = surface.canvas()
canvas.clear("ffffff")
paint = skia.Paint()
paint.antialias = True
paint.color = "000000"
canvas.draw_circle(128, 128, 100, paint)
surface.write_file("out.png")
Modules§
| canvas |
|
| codec | Decoding of encoded images into |
| font |
|
| font_metrics | The metrics of a font. The metric values are consistent with the Skia y-down coordinate system. |
| font_style | Describes the style of a font: weight, width, and slant. |
| image | Describes a two dimensional array of pixels to draw. An |
| image_filter | Base class for image filters: when installed in a |
| matrix | Holds a 3x3 matrix for transforming coordinates. This allows mapping |
| paint |
|
| path | Describes geometry as a set of contours, each beginning with a move verb and followed by lines, quadratic beziers, conics, and cubic beziers. |
| path_builder | Helper to build a |
| path_types | Types used by |
| rrect | Describes a rounded rectangle with a bounds and a pair of radii for each corner. The bounds
and radii can be set so that |
| sampling_options | Options for sampling images: filter mode, mipmap mode, and cubic resampler. |
| shader | Specifies the source color(s) for what is being drawn. If a |
| surface | Describes a drawing destination: a |
| talon | AlphaType, Canvas, Color, ColorType, Image |
| textlayout | TextAlign |
| typeface | Describes the typeface and style of a font; a |
Classes§
| AddMode | |
| AlphaType Enum | Describes how to interpret the alpha component of a pixel. A pixel may be opaque, or alpha, describing multiple levels of transparency. |
| ArcSize | |
| Bitmap |
|
| BlendMode Enum | Blends are operators that take in two colors (source, destination) and return a new color. Many of these operate the same on all 4 components: red, green, blue, alpha. For these, we just document what happens to one component, rather than naming each one separately. |
| Canvas |
|
| ClipOp Enum | |
| Color | 32-bit ARGB color value, unpremultiplied. Color components are always in a known order. This is
different from |
| ColorType Enum | Describes how pixel bits encode color. A pixel may be an alpha mask, a grayscale, RGB, or ARGB. |
| CubicResampler | Specify |
| Data | |
| EncodedImageFormat Enum | Enum describing format of encoded data. |
| FilterMode Enum | |
| FilterQuality | |
| Font |
|
| FontHinting | |
| FontMetrics | |
| FontSlant Enum | |
| Fontstyle | |
| Image |
|
| ImageFilter | |
| ImageInfo | Describes pixel dimensions and encoding. |
| Matrix | |
| Matrix4 | 4x4 matrix used by |
| MipmapMode Enum | |
| Paint |
|
| PaintStyle | |
| Path |
|
| PathBuilder | |
| PathDirection | |
| PathFillType | |
| PixelGeometry Enum | Description of how the LCD strips are arranged for each pixel. If this is unknown, or the
pixels are meant to be "portable" and/or transformed before showing (e.g. rotated, scaled)
then use |
| Point2d | |
| Point3d | |
| PointMode Enum | Selects if an array of points are drawn as discrete points, as lines, or as an open polygon. |
| Rect | |
| RoundRect | |
| SamplingOptions | |
| Shader | |
| StrokeCap Enum |
|
| StrokeJoin Enum |
|
| Surface |
|
| SurfaceProps | Describes properties and constraints of a given surface. The rendering engine can parse these during drawing, and can sometimes optimize its performance (e.g. disabling an expensive feature). |
| SurfacePropsFlags | |
| TextAlign Enum | |
| TextBlob | |
| TileMode Enum | Describes how a shader draws outside of its original bounds: |
| Typeface |
Functions§
Constants§
Re-exports§
| AlphaType | |
| Canvas | |
| Color | |
| ColorType | |
| Image | |
| Paint | |
| Path | |
| Rect | |
| RoundRect | |
| Shader | |
| Surface |