animator.skia.Image

class animator.skia.Image

Bases: pybind11_builtins.pybind11_object

Image describes a two dimensional array of pixels to draw.

A few high-level methods in addition to C++ API:

image = skia.Image.open('/path/to/image.png')
image = image.resize(120, 120)
image = image.convert(alphaType=skia.kUnpremul_AlphaType)
image.save('/path/to/output.jpg', skia.kJPEG)

NumPy arrays can be directly imported or exported:

image = skia.Image.fromarray(array)
array = image.toarray()

General pixel buffers can be exchanged in the following approach:

image = skia.Image.frombytes(pixels, (100, 100))
pixels = image.tobytes()
__init__(*args, **kwargs)

Methods

DeferredFromEncodedData(encoded[, alphaType])

DeferredFromPicture(picture, dimensions, ...)

RasterFromBitmap(bitmap)

RasterFromCompressedTextureData(data, width, ...)

RasterFromData(info, pixels, rowBytes)

RasterFromPixmap(pixmap)

Creates Image from pixmap, sharing Pixmap pixels.

RasterFromPixmapCopy(pixmap)

__init__(*args, **kwargs)

alphaType(self)

bitmap(self, colorType, alphaType, colorSpace)

Creates a new Bitmap from Image with a copy of pixels.

bounds(self)

colorSpace(self)

colorType(self)

dimensions(self)

encodeToData(self, encodedImageFormat, quality)

fromarray(array, ct, at, cs, copy)

Creates a new Image from numpy array.

frombytes(buffer, dimensions, ct, at, cs, copy)

Creates a new Image from bytes.

hasMipmaps(self)

height(self)

imageInfo(self)

isAlphaOnly(self)

isLazyGenerated(self)

isOpaque(self)

isValid(self)

Returns True if Image can be drawn on raster surface.

makeColorSpace(self, target)

Creates Image in target colorspace.

makeColorTypeAndColorSpace(self, ...)

Creates Image in targetColorType and targetColorSpace.

makeNonTextureImage(self)

makeRasterImage(self, cachingHint)

makeRawShader(self, tmx, tmy, sampling, ...)

makeShader(self, tmx, tmy, sampling, localMatrix)

makeSubset(self, subset)

Returns subset of Image with subset bounds.

makeWithFilter(self, filter[, subset, ...])

Creates filtered Image and returns (filteredImage, outSubset, offset).

open(fp)

Opens an image from a file like object or a path.

peekPixels(self)

Returns a Pixmap describing the pixel data.

readPixels(*args, **kwargs)

Overloaded function.

refColorSpace(self)

refEncodedData(self)

reinterpretColorSpace(self, newColorSpace)

resize(self, width, height, sampling, ...)

Creates a new Image by scaling pixels to fit width and height.

save(self, fp, encodedImageFormat, quality)

Saves the image to a file like object or a path.

scalePixels(self, dst, sampling, cachingHint)

toarray(self, srcX, srcY, ct, at, cs)

Returns a ndarray of the image's pixels.

tobytes(self)

Returns python bytes object from internal pixels.

uniqueID(self)

width(self)

withDefaultMipmaps(self)

class BitDepth

Bases: pybind11_builtins.pybind11_object

Members:

kU8

kF16

property name
class CachingHint

Bases: pybind11_builtins.pybind11_object

Members:

kAllow_CachingHint

kDisallow_CachingHint

property name
static DeferredFromEncodedData(encoded: animator.skia.Data, alphaType: Optional[animator.skia.AlphaType] = None) animator.skia.Image
static DeferredFromPicture(picture: animator.skia.Picture, dimensions: animator.skia.ISize, matrix: animator.skia.Matrix = None, paint: animator.skia.Paint = None, bitDepth: animator.skia.Image.BitDepth = <BitDepth.kU8: 0>, colorSpace: animator.skia.ColorSpace = None, props: animator.skia.SurfaceProps = <animator.skia.SurfaceProps object at 0x7f2050114a70>) animator.skia.Image
static RasterFromBitmap(bitmap: SkBitmap) animator.skia.Image
static RasterFromCompressedTextureData(data: animator.skia.Data, width: int, height: int, type: animator.skia.Image.TextureCompressionType) animator.skia.Image
static RasterFromData(info: animator.skia.ImageInfo, pixels: animator.skia.Data, rowBytes: int) animator.skia.Image
static RasterFromPixmap(pixmap: animator.skia.Pixmap) animator.skia.Image

Creates Image from pixmap, sharing Pixmap pixels.

static RasterFromPixmapCopy(pixmap: animator.skia.Pixmap) animator.skia.Image
class TextureCompressionType

Bases: pybind11_builtins.pybind11_object

Members:

kNone

kETC2_RGB8_UNORM

kBC1_RGB8_UNORM

kBC1_RGBA8_UNORM

kLast

kETC1_RGB8

property name
alphaType(self: animator.skia.Image) animator.skia.AlphaType
bitmap(self: animator.skia.Image, colorType: animator.skia.ColorType = <ColorType.kUnknown_ColorType: 0>, alphaType: animator.skia.AlphaType = <AlphaType.kUnknown_AlphaType: 0>, colorSpace: animator.skia.ColorSpace = None) SkBitmap

Creates a new Bitmap from Image with a copy of pixels.

bounds(self: animator.skia.Image) animator.skia.IRect
colorSpace(self: animator.skia.Image) animator.skia.ColorSpace
colorType(self: animator.skia.Image) animator.skia.ColorType
dimensions(self: animator.skia.Image) animator.skia.ISize
encodeToData(self: animator.skia.Image, encodedImageFormat: animator.skia.EncodedImageFormat = <EncodedImageFormat.kPNG: 4>, quality: int = 100) animator.skia.Data
static fromarray(array: numpy.ndarray, ct: animator.skia.ColorType = <ColorType.kRGBA_8888_ColorType: 4>, at: animator.skia.AlphaType = <AlphaType.kUnpremul_AlphaType: 3>, cs: animator.skia.ColorSpace = None, copy: bool = True) animator.skia.Image

Creates a new Image from numpy array.

Parameters
  • array – A numpy array of shape (height, width, channels) and appropriate dtype.

  • ct – The color type of the image.

  • at – The alpha type of the image.

  • cs – The color space of the image.

  • copy – Whether to copy the data from the array.

Returns

A new Image sharing the data in the array if copy is False, or a new Image with a copy of the data if copy is True.

static frombytes(buffer: buffer, dimensions: animator.skia.ISize, ct: animator.skia.ColorType = <ColorType.kRGBA_8888_ColorType: 4>, at: animator.skia.AlphaType = <AlphaType.kUnpremul_AlphaType: 3>, cs: animator.skia.ColorSpace = None, copy: bool = True) animator.skia.Image

Creates a new Image from bytes.

Parameters
  • buffer – A Python buffer object.

  • dimensions – The dimensions of the image.

  • ct – The color type of the image.

  • at – The alpha type of the image.

  • cs – The color space of the image.

  • copy – Whether to copy the data from the buffer.

Returns

A new Image sharing the data in the buffer if copy is False, or a new Image with a copy of the data if copy is True.

hasMipmaps(self: animator.skia.Image) bool
height(self: animator.skia.Image) int
imageInfo(self: animator.skia.Image) animator.skia.ImageInfo
isAlphaOnly(self: animator.skia.Image) bool
isLazyGenerated(self: animator.skia.Image) bool
isOpaque(self: animator.skia.Image) bool
isValid(self: animator.skia.Image) bool

Returns True if Image can be drawn on raster surface.

makeColorSpace(self: animator.skia.Image, target: animator.skia.ColorSpace) animator.skia.Image

Creates Image in target colorspace.

makeColorTypeAndColorSpace(self: animator.skia.Image, targetColorType: animator.skia.ColorType, targetColorSpace: animator.skia.ColorSpace) animator.skia.Image

Creates Image in targetColorType and targetColorSpace.

makeNonTextureImage(self: animator.skia.Image) animator.skia.Image
makeRasterImage(self: animator.skia.Image, cachingHint: animator.skia.Image.CachingHint = <CachingHint.kDisallow_CachingHint: 1>) animator.skia.Image
makeRawShader(self: animator.skia.Image, tmx: animator.skia.TileMode = <TileMode.kClamp: 0>, tmy: animator.skia.TileMode = <TileMode.kClamp: 0>, sampling: animator.skia.SamplingOptions = <animator.skia.SamplingOptions object at 0x7f20500d9a30>, localMatrix: animator.skia.Matrix = None) SkShader
makeShader(self: animator.skia.Image, tmx: animator.skia.TileMode = <TileMode.kClamp: 0>, tmy: animator.skia.TileMode = <TileMode.kClamp: 0>, sampling: animator.skia.SamplingOptions = <animator.skia.SamplingOptions object at 0x7f2050107df0>, localMatrix: animator.skia.Matrix = None) SkShader
makeSubset(self: animator.skia.Image, subset: animator.skia.IRect) animator.skia.Image

Returns subset of Image with subset bounds.

makeWithFilter(self: animator.skia.Image, filter: SkImageFilter, subset: animator.skia.IRect = None, clipBounds: animator.skia.IRect = None) tuple

Creates filtered Image and returns (filteredImage, outSubset, offset).

static open(fp: object) animator.skia.Image

Opens an image from a file like object or a path.

peekPixels(self: animator.skia.Image) animator.skia.Pixmap

Returns a Pixmap describing the pixel data.

readPixels(*args, **kwargs)

Overloaded function.

  1. readPixels(self: animator.skia.Image, dstInfo: animator.skia.ImageInfo, dstPixels: buffer, dstRowBytes: int = 0, srcX: int = 0, srcY: int = 0, cachingHint: animator.skia.Image.CachingHint = <CachingHint.kAllow_CachingHint: 0>) -> bool

Copies dstInfo pixels starting from (srcX, srcY) to dstPixels buffer.

  1. readPixels(self: animator.skia.Image, dst: animator.skia.Pixmap, srcX: int = 0, srcY: int = 0, cachingHint: animator.skia.Image.CachingHint = <CachingHint.kAllow_CachingHint: 0>) -> bool

Copies pixels starting from (srcX, srcY) to dst Pixmap.

refColorSpace(self: animator.skia.Image) animator.skia.ColorSpace
refEncodedData(self: animator.skia.Image) animator.skia.Data
reinterpretColorSpace(self: animator.skia.Image, newColorSpace: animator.skia.ColorSpace) animator.skia.Image
resize(self: animator.skia.Image, width: int, height: int, sampling: animator.skia.SamplingOptions = <animator.skia.SamplingOptions object at 0x7f20529a8330>, cachingHint: animator.skia.Image.CachingHint = <CachingHint.kAllow_CachingHint: 0>) animator.skia.Image

Creates a new Image by scaling pixels to fit width and height.

save(self: animator.skia.Image, fp: object, encodedImageFormat: animator.skia.EncodedImageFormat = <EncodedImageFormat.kPNG: 4>, quality: int = 100) None

Saves the image to a file like object or a path.

Parameters
  • fp – A file like object or a path.

  • format – The format of the image. Should be one of EncodedImageFormat.kJPEG, EncodedImageFormat.kPNG, EncodedImageFormat.kWEBP.

  • quality – The quality of the image. 100 is the best quality.

scalePixels(self: animator.skia.Image, dst: animator.skia.Pixmap, sampling: animator.skia.SamplingOptions = <animator.skia.SamplingOptions object at 0x7f20529b96b0>, cachingHint: animator.skia.Image.CachingHint = <CachingHint.kAllow_CachingHint: 0>) bool
toarray(self: animator.skia.Image, srcX: int = 0, srcY: int = 0, ct: animator.skia.ColorType = <ColorType.kRGBA_8888_ColorType: 4>, at: animator.skia.AlphaType = <AlphaType.kUnpremul_AlphaType: 3>, cs: animator.skia.ColorSpace = None) numpy.ndarray

Returns a ndarray of the image’s pixels.

tobytes(self: animator.skia.Image) bytes

Returns python bytes object from internal pixels.

uniqueID(self: animator.skia.Image) int
width(self: animator.skia.Image) int
withDefaultMipmaps(self: animator.skia.Image) animator.skia.Image