Bitmap
public final class 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 Canvas. Bitmap can be a drawing destination for 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 Surface for better performance.
Bitmap is not thread safe. Each thread must have its own copy of Bitmap fields, although threads may share the underlying pixel array.
-
Creates an empty Bitmap without pixels, with
colorTypeset to.unkonwnalphaTypeset to.unknown, and with a width and height of zero. PixelRef origin is set to (0, 0). Bitmap is not volatile.Declaration
Swift
public init()Return Value
empty Bitmap example: https://fiddle.skia.org/c/@Bitmap_empty_constructor
-
Undocumented
Declaration
Swift
public convenience init(_ width: Int32, _ height: Int32, isOpaque: Bool = false) throws -
Undocumented
Declaration
Swift
public init(_ imageInfo: ImageInfo, rowBytes: Int? = nil) throws -
Returns row bytes, the interval from one pixel row to the next. Row bytes is at least as large as:
width*imageInfo.bytesPerPixel. Returns zero if colorType is.unknown, or if row bytes supplied to setInfo() is not large enough to hold a row of pixels.Declaration
Swift
public var rowBytes: Int { get }Return Value
byte length of pixel row
-
Sets
ImageInfoto info following and allocates pixel memory.rowBytesmust equal or exceedinfo.widthtimesinfo.bytesPerPixel, or equal zero. Pass in zero forrowBytesto compute the minimum valid value. Returnsfalseand callsreset()ifImageInfocould not be set, or memory could not be allocated.On most platforms, allocating pixel memory may succeed even though there is not sufficient memory to hold pixels; allocation does not take place until the pixels are written to. The actual behavior depends on the platform implementation of malloc().
Declaration
Swift
public func tryAllocPixels(info: sk_imageinfo_t, rowBytes: Int? = nil) -> BoolParameters
infocontains width, height,
AlphaType,ColorType,ColorSpacerowBytessize of pixel row or larger; may be zero
Return Value
true if pixel storage is allocated
-
Resets to its initial state; all fields are set to zero, as if
Bitmaphad been initialized byBitmap().Sets
width,height,row bytesto zero; pixel address tonil;ColorTypeto.unknown; andAlphaTypeto.unknown.If
PixelRefis allocated, its reference count is decreased by one, releasing its memory ifBitmapis the sole owner.Declaration
Swift
public func reset() -
Sets internal flag to mark
Bitmapas immutable. Once set, pixels can not change. Any other bitmap sharing the samePixelRefare also marked as immutable. OncePixelRefis marked immutable, the setting cannot be cleared. Writing to immutableBitmappixels triggers an assert on debug builds. example: https://fiddle.skia.org/c/@Bitmap_setImmutableDeclaration
Swift
public func setImmutable() -
Replaces pixel values with c. All pixels contained by the bounds are affected. If the
colorTypeis.gray9or.krgb565, then alpha is ignored; RGB is treated as opaque. If colorType is.alpha8then RGB is ignored.Declaration
Swift
public func erase(_ color: Color)Parameters
cunpremultiplied color example: https://fiddle.skia.org/c/@Bitmap_eraseColor
-
Undocumented
-
Undocumented
Declaration
Swift
public func getAddr8(x: Int32, y: Int32) -> UInt8 -
Undocumented
Declaration
Swift
public func getAddr16(x: Int32, y: Int32) -> UInt16 -
Undocumented
Declaration
Swift
public func getAddr32(x: Int32, y: Int32) -> UInt32 -
Undocumented
Declaration
Swift
public func getAddr64(x: Int32, y: Int32) -> UnsafeMutableRawPointer? -
Undocumented
Declaration
Swift
public func getPixel(x: Int32, y: Int32) -> Color -
Undocumented
Declaration
Swift
public func setPixel(x: Int32, y: Int32, value: Color) -
Undocumented
Declaration
Swift
public func canCopy(to colorType: ColorType) -> Bool -
Undocumented
Declaration
Swift
public var imageInfo: ImageInfo { get } -
Undocumented
Declaration
Swift
public var width: Int32 { get } -
Undocumented
Declaration
Swift
public var height: Int32 { get } -
Undocumented
Declaration
Swift
public var alphaType: AlphaType { get } -
Undocumented
Declaration
Swift
public var bytesPerPixel: Int32 { get } -
Undocumented
Declaration
Swift
public var colorType: ColorType { get } -
Undocumented
Declaration
Swift
public var byteCount: Int { get } -
Undocumented
Declaration
Swift
public func getPixels() -> (buffer: UnsafeMutableRawPointer?, len: Int) -
Undocumented
Declaration
Swift
public func setPixels(buffer: UnsafeMutableRawPointer) -
Returns the pixels if they are available without having to lock the bitmap.
Declaration
Swift
public func peekPixels() -> Pixmap?Return Value
Returns the pixels if they are available, otherwise null.
-
Returns the pixmap of the bitmap
Declaration
Swift
public func peekPixels(_ pixmap: Pixmap) -> BoolReturn Value
true on success, false on failure
View on GitHub
Install in Dash
Bitmap Class Reference