S or /

SourceClass Image

from skia import Image
class Image:

Image describes a two dimensional array of pixels to draw. The pixels may be decoded in a raster bitmap, encoded in a Picture or compressed data stream, or located in GPU memory as a GPU texture.

Image cannot be modified after it is created. Image may allocate additional storage as needed; for instance, an encoded Image may decode when drawn.

Image width and height are greater than zero. Creating an Image with zero width or height returns Image equal to None.

Image may be created from Bitmap, Pixmap, skia.Surface, Picture, encoded streams, GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details vary with platform.

Constants§

AlphaType: Final[type]§
ColorType: Final[type]§

Properties§

Source@property def alpha_type(self, /) -> AlphaType§

Returns AlphaType.

AlphaType returned was a parameter to an Image constructor, or was parsed from encoded data.

Returns: AlphaType in Image

Example (C++): https://fiddle.skia.org/c/@Image_alphaType

Source@property def color_type(self, /) -> ColorType§

Returns ColorType if known; otherwise, returns ColorType.UNKNOWN.

Returns: ColorType of Image

Example (C++): https://fiddle.skia.org/c/@Image_colorType

Source@property def height(self, /) -> int§

Returns pixel row count.

Returns: pixel height in Image

@property def rect(self, /) -> Rect |None§
@rect.setter def rect(self, /, value: Rect |None) -> None§
@property def retina(self, /) -> bool |None§
@retina.setter def retina(self, /, value: bool |None) -> None§
Source@property def unique_id(self, /) -> int§

Returns value unique to image. Image contents cannot change after Image is created. Any operation to create a new Image will receive generate a new unique number.

Returns: unique identifier

Source@property def width(self, /) -> int§

Returns pixel count in each row.

Returns: pixel width in Image

Methods§

def encode(self, /, fmt: EncodedImageFormat |None = None, quality: int |None = None) -> Data§
@classmethod def from_array(cls, /, array: Any) -> Image§
Source@classmethod def from_bitmap(cls, /, bitmap: Bitmap) -> Image§

Creates Image from bitmap, sharing or copying bitmap pixels. If the bitmap is marked immutable, and its pixel memory is shareable, it may be shared instead of copied.

Image is returned if bitmap is valid. Valid Bitmap parameters include: dimensions are greater than zero; each dimension fits in 29 bits; ColorType and AlphaType are valid, and ColorType is not ColorType.UNKNOWN; row bytes are large enough to hold one row of pixels; pixel address is not null.

Returns: created Image, or None

Source@classmethod def from_encoded(cls, /, data: Data) -> Image§
@classmethod def from_file(cls, /, path: Any) -> Image§
@classmethod def from_pixels(cls, /, data: bytes, stride: int, width: int, height: int, color_type: ColorType |None = None, alpha_type: AlphaType |None = None) -> Image§
Sourcedef is_alpha_only(self, /) -> bool§

Returns True if Image pixels represent transparency only. If True, each pixel is packed in 8 bits as defined by ColorType.Alpha8.

Returns: True if pixels represent a transparency mask

Example (C++): https://fiddle.skia.org/c/@Image_isAlphaOnly

Sourcedef is_lazy_generated(self, /) -> bool§

Returns True if Image is backed by an image-generator or other service that creates and caches its pixels or texture on-demand.

Returns: True if Image is created as needed

Example (C++): https://fiddle.skia.org/c/@Image_isLazyGenerated_a Example (C++): https://fiddle.skia.org/c/@Image_isLazyGenerated_b

Sourcedef is_texture_backed(self, /) -> bool§

Returns True if the contents of Image was created on or uploaded to GPU memory, and is available as a GPU texture.

Returns: True if Image is a GPU texture

Example (C++): https://fiddle.skia.org/c/@Image_isTextureBacked

@classmethod def load(cls, /, path: Any) -> Image§
def make_shader(self, /, tile_x: TileMode, tile_y: TileMode, local_matrix: Matrix |None = None) -> Shader§
Sourcedef make_subset(self, /, subset: tuple[int, int, int, int]) -> Image§

Returns subset of this image.

Returns None if any of the following are true: - Subset is empty - Subset is not contained inside the image's bounds - Pixels in the image could not be read or copied - This image is texture-backed and the provided context is null or does not match the source image's context.

If the source image was texture-backed, the resulting image will be texture-backed also. Otherwise, the returned image will be raster-backed.

                       source image was texture-backed).
  • subset - bounds of returned Image

Returns: the subsetted image, or None

Sourcedef read_pixels(self, /, x: int, y: int, width: int, height: int, color_type: ColorType |None = None, alpha_type: AlphaType |None = None) -> bytes§
def reshape(self, /, width: int |None = None, height: int |None = None, color_type: ColorType |None = None, alpha_type: AlphaType |None = None) -> Image§
def save(self, /, path: Any) -> None§
def to_bitmap(self, /) -> Bitmap§
def write_file(self, /, path: Any) -> None§