Bitmaps and Geometry¶
Rendering produces a novasvg.Bitmap; novasvg.Matrix,
novasvg.Box and novasvg.Color are the small value types used
for transforms, bounding boxes and colors.
Reference¶
- class Bitmap(*args, **kwargs)¶
- clear(self, value: novasvg.Color) None¶
- clear(self, value: int) None
Overloaded function.
clear(self, value: novasvg.Color) -> None
Clear the bitmap with a Color.
clear(self, value: int) -> None
Clear the bitmap with a packed 0xRRGGBBAA value.
- convert_to_rgba(self) None¶
Convert pixel data in place from ARGB32 Premultiplied to RGBA Plain. Only needed to hand the raw buffer to something else (e.g. numpy consumers wanting straight RGBA); NOT before write_to_*/to_*/write, which convert internally – doing both converts twice.
- is_null(self) bool¶
Check if the bitmap is null.
- numpy(self) numpy.ndarray[dtype=uint8]¶
Get pixel data as a NumPy array.
- to_bmp(self) bytes¶
Encode the bitmap as BMP and return the file contents as bytes.
- to_bytes(self, format: str = 'png', quality: int = 80) bytes¶
Encode the bitmap in the given format (‘png’, ‘bmp’, ‘tga’, ‘jpg’/’jpeg’; a leading ‘.’ and any letter case are accepted) and return the file contents as bytes. quality (1-100) is used only for JPEG.
- to_jpg(self, quality: int = 80) bytes¶
Encode the bitmap as JPEG (quality 1-100) and return the file contents as bytes. JPEG has no alpha channel: render onto an opaque background first.
- to_png(self) bytes¶
Encode the bitmap as PNG and return the file contents as bytes (no temp file).
- to_tga(self) bytes¶
Encode the bitmap as TGA and return the file contents as bytes.
- write(self, filename: str, jpg_quality: int = 80) bool¶
Write the bitmap to a file, picking PNG/BMP/TGA/JPEG from the extension (.png/.bmp/.tga/.jpg/.jpeg; PNG if unrecognized). Returns True on success.
- write_to_bmp(self, filename: str) bool¶
Write the bitmap to a BMP file. Returns True on success.
- write_to_jpg(self, filename: str, quality: int = 80) bool¶
Write the bitmap to a JPEG file (quality 1-100). JPEG has no alpha channel: render onto an opaque background first. Returns True on success.
- write_to_png(self, filename: str) bool¶
Write the bitmap to a PNG file. Returns True on success.
- write_to_tga(self, filename: str) bool¶
Write the bitmap to a TGA file. Returns True on success.
- property height¶
Get the height of the bitmap.
- property stride¶
Get the stride (bytes per row) of the bitmap.
- property width¶
Get the width of the bitmap.
- class Matrix(*args, **kwargs)¶
- inverse(self) novasvg.Matrix¶
Return a new inverted matrix.
- invert(self) novasvg.Matrix¶
Invert this matrix in place.
- multiply(self, arg: novasvg.Matrix, /) novasvg.Matrix¶
Multiply this matrix by another.
- reset(self) None¶
Reset the matrix to identity.
- rotate(self, angle: float, cx: float = 0.0, cy: float = 0.0) novasvg.Matrix¶
Rotate the matrix around a point.
- scale(self, sx: float, sy: float) novasvg.Matrix¶
Scale the matrix.
- translate(self, tx: float, ty: float) novasvg.Matrix¶
Translate the matrix.
- property a¶
Horizontal scaling factor.
- property b¶
Vertical shearing factor.
- property c¶
Horizontal shearing factor.
- property d¶
Vertical scaling factor.
- property e¶
Horizontal translation offset.
- property f¶
Vertical translation offset.
- rotated = <nanobind.nb_func object>¶
- scaled = <nanobind.nb_func object>¶
- translated = <nanobind.nb_func object>¶
- class Box(*args, **kwargs)¶
- transform(self, matrix: novasvg.Matrix) novasvg.Box¶
Transform the box by a matrix in place.
- transformed(self, matrix: novasvg.Matrix) novasvg.Box¶
Return a new transformed box.
- property h¶
Height of the box.
- property w¶
Width of the box.
- property x¶
X-coordinate of the box.
- property y¶
Y-coordinate of the box.
- class Color(*args, **kwargs)¶
- to_int(self) int¶
- value(self) int¶
Get the color packed as a 0xRRGGBBAA integer.
- property a¶
(self) -> int
- property b¶
(self) -> int
- black = <nanobind.nb_func object>¶
- blue = <nanobind.nb_func object>¶
- cyan = <nanobind.nb_func object>¶
- from_hash = <nanobind.nb_func object>¶
- from_name = <nanobind.nb_func object>¶
- from_value = <nanobind.nb_func object>¶
- property g¶
(self) -> int
- green = <nanobind.nb_func object>¶
- magenta = <nanobind.nb_func object>¶
- orange = <nanobind.nb_func object>¶
- property r¶
(self) -> int
- red = <nanobind.nb_func object>¶
- rgba = <nanobind.nb_func object>¶
- transparent = <nanobind.nb_func object>¶
- white = <nanobind.nb_func object>¶
- yellow = <nanobind.nb_func object>¶