SourceClass Bitmap
from skia import Bitmapclass Bitmap:Bitmap describes a two-dimensional raster pixel array. Bitmap is built on ImageInfo,
containing integer width and height, ColorType and AlphaType describing the pixel
format, and ColorSpace describing the range of colors. Bitmap points to PixelRef,
which describes the physical array of pixels. ImageInfo bounds may be located anywhere fully
inside PixelRef bounds.
Bitmap can be drawn using skia.Canvas. Bitmap can be a drawing destination for
skia.Canvas draw member functions. Bitmap flexibility as a pixel container limits some
optimizations available to the target platform.
If pixel array is primarily read-only, use Image for better performance.
If pixel array is primarily written to, use skia.Surface for better performance.
Declaring Bitmap const prevents altering ImageInfo: the Bitmap height, width, and so
on cannot change. It does not affect PixelRef: a caller may write its pixels. Declaring
Bitmap const affects Bitmap configuration, not its contents.
Bitmap is not thread safe. Each thread must have its own copy of Bitmap fields, although
threads may share the underlying pixel array.
Properties§
@property
def byte_count(self, /) -> int§
Source@property
def info(self, /) -> ImageInfo§
Returns width, height, AlphaType, ColorType, and ColorSpace.
Source@property
def pixels(self, /) -> Any§
Returns pixel address, the base address corresponding to the pixel origin.
@pixels.setter
def pixels(self, /, _value: tuple[bytes, Any |None]) -> None§
Source@property
def row_bytes(self, /) -> int§
Returns row bytes, the interval from one pixel row to the next. Row bytes is at least as
large as: width() * info().bytes_per_pixel().
Returns zero if color_type() is ColorType.UNKNOWN, or if row bytes supplied to
set_info() is not large enough to hold a row of pixels.
Methods§
Sourcedef erase(self, /, color: Any) -> None§
Replaces pixel values inside area with c. interpreted as being in the sRGB ColorSpace.
If area does not intersect bounds(), call has no effect.
If the color_type() is ColorType.Gray8 ColorType.RGB565, then alpha is ignored;
RGB is treated as opaque. If color_type() is ColorType.Alpha8, then RGB is ignored.
Input color is ultimately converted to an Color4f, so skia.Bitmap.erase_4f will have
higher color resolution.
Example (C++): https://fiddle.skia.org/c/@Bitmap_erase
def get_colortable(self, /) -> Any |None§
def get_pixel(self, /, x: int, y: int) -> Color§
Sourcedef is_immutable(self, /) -> bool§
Returns True if pixels can not change.
Most immutable Bitmap checks trigger an assert only on debug builds.
Example (C++): https://fiddle.skia.org/c/@Bitmap_isImmutable
Sourcedef is_null(self, /) -> bool§
def make_canvas(self, /) -> Canvas§
def make_image(self, /) -> Image§
Sourcedef notify_pixels_changed(self, /) -> None§
Marks that pixels in PixelRef have changed. Subsequent calls to generation_id() return
a different value.
Example (C++): https://fiddle.skia.org/c/@Bitmap_notifyPixelsChanged
Sourcedef reset(self, /) -> None§
Resets to its initial state; all fields are set to zero, as if Bitmap had
been initialized by Bitmap().
Sets width, height, row bytes to zero; pixel address to None; ColorType to
ColorType.UNKNOWN; and AlphaType to AlphaType.UNKNOWN.
If PixelRef is allocated, its reference count is decreased by one, releasing its memory
if Bitmap is the sole owner.
Example (C++): https://fiddle.skia.org/c/@Bitmap_reset
Sourcedef set_immutable(self, /) -> None§
Sets internal flag to mark Bitmap as immutable. Once set, pixels can not change. Any
other bitmap sharing the same PixelRef are also marked as immutable.
Once PixelRef is marked immutable, the setting cannot be cleared.
Writing to immutable Bitmap pixels triggers an assert on debug builds.
Example (C++): https://fiddle.skia.org/c/@Bitmap_setImmutable