SkImage related constants are defined by enum, enum class, #define, const, and constexpr.
SkImage typedef define a data type.
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 nullptr.
Image may be created from Bitmap, Pixmap, 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.
Raster Image pixels are decoded in a Raster Bitmap. These pixels may be read directly and in most cases written to, although edited pixels may not be drawn if Image has been copied internally.
Texture Image are located on GPU and pixels are not accessible. Texture Image are allocated optimally for best performance. Raster Image may be drawn to GPU Surface, but pixels are uploaded from CPU to GPU downgrading performance.
Lazy Image defer allocating buffer for Image pixels and decoding stream until Image is drawn. Lazy Image caches result if possible to speed up repeated drawing.
SkImage global, struct, and class related member functions share a topic.
SkImage can be constructed or initialized by these functions, including C++ class constructors.
SkImage member functions read and modify the structure properties.
Creates Image from Pixmap and copy of pixels. Since pixels are copied, Pixmap pixels may be modified or deleted without affecting Image.
Image is returned if Pixmap is valid. Valid Pixmap parameters include: dimensions are greater than zero; each dimension fits in 29 bits; Color Type and Alpha Type are valid, and Color Type is not kUnknown_SkColorType; row bytes are large enough to hold one row of pixels; pixel address is not nullptr.
copy of Pixmap pixels, or nullptr
MakeRasterData MakeFromGenerator
Creates Image from Image Info, sharing pixels.
Image is returned if Image Info is valid. Valid Image Info parameters include: dimensions are greater than zero; each dimension fits in 29 bits; Color Type and Alpha Type are valid, and Color Type is not kUnknown_SkColorType; rowBytes are large enough to hold one row of pixels; pixels is not nullptr, and contains enough data for Image.
Image sharing pixels, or nullptr
MakeRasterCopy MakeFromGenerator
Caller data passed to RasterReleaseProc; may be nullptr.
MakeFromRaster RasterReleaseProc
Function called when Image no longer shares pixels. ReleaseContext is provided by caller when Image is created, and may be nullptr.
ReleaseContext MakeFromRaster
Creates Image from pixmap, sharing Pixmap pixels. Pixels must remain valid and unchanged until rasterReleaseProc is called. rasterReleaseProc is passed releaseContext when Image is deleted or no longer refers to pixmap pixels.
Pass nullptr for rasterReleaseProc to share Pixmap without requiring a callback when Image is released. Pass nullptr for releaseContext if rasterReleaseProc does not require state.
Image is returned if pixmap is valid. Valid Pixmap parameters include: dimensions are greater than zero; each dimension fits in 29 bits; Color Type and Alpha Type are valid, and Color Type is not kUnknown_SkColorType; row bytes are large enough to hold one row of pixels; pixel address is not nullptr.
Image sharing pixmap
before reset: 0 after reset: 1
MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext
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; Color Type and Alpha Type are valid, and Color Type is not kUnknown_SkColorType; row bytes are large enough to hold one row of pixels; pixel address is not nullptr.
created Image, or nullptr
MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData
Creates Image from data returned by imageGenerator. Generated data is owned by Image and may not be shared or accessed.
subset allows selecting a portion of the full image. Pass nullptr to select the entire image; otherwise, subset must be contained by image bounds.
Image is returned if generator data is valid. Valid data parameters vary by type of data and platform.
imageGenerator may wrap Picture data, codec data, or custom data.
created Image, or nullptr
MakeFromEncoded
Creates Image from encoded data. subset allows selecting a portion of the full image. Pass nullptr to select the entire image; otherwise, subset must be contained by image bounds.
Image is returned if format of the encoded data is recognized and supported. Recognized formats vary by platform.
created Image, or nullptr
MakeFromGenerator
User function called when supplied texture may be deleted.
MakeFromTexture[2]
Creates Image from GPU Texture associated with context. Caller is responsible for managing the lifetime of GPU Texture.
Image is returned if format of backendTexture is recognized and supported. Recognized formats vary by GPU back-end.
created Image, or nullptr
MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Creates Image from GPU Texture associated with context. GPU Texture must stay valid and unchanged until textureReleaseProc is called. textureReleaseProc is passed releaseContext when Image is deleted or no longer refers to texture.
Image is returned if format of backendTexture is recognized and supported. Recognized formats vary by GPU back-end.
created Image, or nullptr
MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Creates Image from encoded data. Image is uploaded to GPU back-end using context.
Created Image is available to other GPU contexts, and is available across thread boundaries. All contexts must be in the same GPU Share Group, or otherwise share resources.
When Image is no longer referenced, context releases texture memory asynchronously.
Texture decoded from data is uploaded to match Surface created with dstColorSpace. Color Space of Image is determined by encoded data.
Image is returned if format of data is recognized and supported, and if context supports moving resources. Recognized formats vary by platform and GPU back-end.
Image is returned using MakeFromEncoded if context is nullptr or does not support moving resources between contexts.
created Image, or nullptr
MakeCrossContextFromPixmap
Creates Image from pixmap. Image is uploaded to GPU back-end using context.
Created Image is available to other GPU contexts, and is available across thread boundaries. All contexts must be in the same GPU Share Group, or otherwise share resources.
When Image is no longer referenced, context releases texture memory asynchronously.
Texture created from pixmap is uploaded to match Surface created with dstColorSpace. Color Space of Image is determined by pixmap.colorSpace.
Image is returned referring to GPU back-end if context is not nullptr, format of data is recognized and supported, and if context supports moving resources between contexts. Otherwise, pixmap pixel data is copied and Image as returned in raster format if possible; nullptr may be returned. Recognized GPU formats vary by platform and GPU back-end.
created Image, or nullptr
MakeCrossContextFromEncoded
Creates Image from backendTexture associated with context. backendTexture and returned Image are managed internally, and are released when no longer needed.
Image is returned if format of backendTexture is recognized and supported. Recognized formats vary by GPU back-end.
created Image, or nullptr
MakeFromTexture[2] MakeFromYUVTexturesCopy
Creates Image from copy of yuvTextures, an array of textures on GPU. yuvTextures contain pixels for YUV planes of Image. Returned Image has the dimensions yuvTextures[0]. yuvColorSpace describes how YUV colors convert to RGB colors.
created Image, or nullptr
MakeFromNV12TexturesCopy
Creates Image from copy of nv12Textures, an array of textures on GPU. nv12Textures[0] contains pixels for YUV Component Y plane. nv12Textures[1] contains pixels for YUV Component U plane, followed by pixels for YUV Component V plane. Returned Image has the dimensions nv12Textures[2]. yuvColorSpace describes how YUV colors convert to RGB colors.
created Image, or nullptr
MakeFromYUVTexturesCopy
MakeFromPicture
Creates Image from picture. Returned Image width and height are set by dimensions. Image draws picture with matrix and paint, set to bitDepth and colorSpace.
If matrix is nullptr, draws with identity Matrix. If paint is nullptr, draws with default Paint. colorSpace may be nullptr.
created Image, or nullptr
SkCanvas::drawPicture[2][3][4]
Creates Image from Android hardware buffer. Returned Image takes a reference on the buffer.
Only available on Android, when ANDROID_API is defined to be 26 or greater.
created Image, or nullptr
MakeFromRaster
Returns pixel count in each row.
pixel width in Image
dimensions height
Returns pixel row count.
pixel height in Image
dimensions width
Returns ISize { width, height }.
integral size of width and height
dimensionsAsBounds == bounds
height width bounds
Returns IRect { 0, 0, width, height }.
integral rectangle from origin to width and height
dimensions
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.
unique identifier
isLazyGenerated
Returns Alpha Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType.
Alpha Type returned was a parameter to an Image constructor, or was parsed from encoded data.
Alpha Type in Image
SkImageInfo::alphaType
Returns Color Type if known; otherwise, returns kUnknown_SkColorType.
Color Type of Image
SkImageInfo::colorType
Returns Color Space, the range of colors, associated with Image. The reference count of Color Space is unchanged. The returned Color Space is immutable.
Color Space returned was passed to an Image constructor, or was parsed from encoded data. Color Space returned may be ignored when Image is drawn, depending on the capabilities of the Surface receiving the drawing.
Color Space in Image, or nullptr
refColorSpace makeColorSpace
Returns a smart pointer to Color Space, the range of colors, associated with Image. The smart pointer tracks the number of objects sharing this SkColorSpace reference so the memory is released when the owners destruct.
The returned SkColorSpace is immutable.
Color Space returned was passed to an Image constructor, or was parsed from encoded data. Color Space returned may be ignored when Image is drawn, depending on the capabilities of the Surface receiving the drawing.
Color Space in Image, or nullptr, wrapped in a smart pointer
colorSpace makeColorSpace
Returns true if Image pixels represent transparency only. If true, each pixel is packed in 8 bits as defined by kAlpha_8_SkColorType.
true if pixels represent a transparency mask
alphaOnly = true
alphaType isOpaque
Returns true if pixels ignore their Alpha value and are treated as fully opaque.
true if Alpha Type is kOpaque_SkAlphaType
isOpaque = false isOpaque = true
alphaType isAlphaOnly
Creates Shader from Image. Shader dimensions are taken from Image. Shader uses SkShader::TileMode rules to fill drawn area outside Image. localMatrix permits transforming Image before Canvas Matrix is applied.
Shader containing Image
scalePixels
Creates Shader from Image. Shader dimensions are taken from Image. Shader uses SkShader::kClamp TileMode to fill drawn area outside Image. localMatrix permits transforming Image before Canvas Matrix is applied.
Shader containing Image
scalePixels
Copies Image pixel address, row bytes, and Image Info to pixmap, if address is available, and returns true. If pixel address is not available, return false and leave pixmap unchanged.
true if Image has direct access to pixels
------------ --xx----x--- -x--x--x---- -x--x--x---- -x--x-x----- --xx-xx-xx-- -----x-x--x- ----x--x--x- ----x--x--x- ---x----xx-- ------------
readPixels[2]
Deprecated.
Returns true the contents of Image was created on or uploaded to GPU memory, and is available as a GPU Texture.
true if Image is a GPU Texture
MakeFromTexture[2] isValid
Returns true if Image can be drawn on either Raster Surface or GPU Surface. If context is nullptr, tests if Image draws on Raster Surface; otherwise, tests if Image draws on GPU Surface associated with context.
Image backed by GPU Texture may become invalid if associated GrContext is invalid. Lazy Image may be invalid and may not draw to Raster Surface or GPU Surface or both.
true if Image can be drawn
isTextureBacked isLazyGenerated
Retrieves the back-end texture. If Image has no back-end texture, an invalid object is returned. Call GrBackendTexture::isValid to determine if the result is valid.
If flushPendingGrContextIO is true, completes deferred I/O operations.
If origin in not nullptr, copies location of content drawn into Image.
back-end API texture handle; invalid on failure
MakeFromTexture[2] isTextureBacked
CachingHint selects whether Skia may internally cache Bitmaps generated by decoding Image, or by copying Image from GPU to CPU. The default behavior allows caching Bitmaps.
Choose kDisallow CachingHint if Image pixels are to be used only once, or if Image pixels reside in a cache outside of Skia, or to reduce memory pressure.
Choosing kAllow CachingHint does not ensure that pixels will be cached. Image pixels may not be cached if memory requirements are too large or pixels are not accessible.
readPixels[2] scalePixels
Copies Rect of pixels from Image to dstPixels. Copy starts at offset (srcX, srcY), and does not exceed Image (width, height).
dstInfo specifies width, height, Color Type, Alpha Type, and Color Space of destination. dstRowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:
Pixels are copied only if pixel conversion is possible. If Image Color Type is kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. If Image Color Type is kGray_8_SkColorType, dstInfo.colorSpace must match. If Image Alpha Type is kOpaque_SkAlphaType, dstInfo.alphaType must match. If Image Color Space is nullptr, dstInfo.colorSpace must match. Returns false if pixel conversion is not possible.
srcX and srcY may be negative to copy only top or left of source. Returns false if width or height is zero or negative. Returns false ifabs(srcX) >= Image width, or ifabs(srcY) >= Image height.
If cachingHint is kAllow CachingHint, pixels may be retained locally. If cachingHint is kDisallow CachingHint, pixels are not added to the local cache.
true if pixels are copied to dstPixels
scalePixels SkBitmap::readPixels[2][3][4] SkPixmap::readPixels[2][3][4][5] SkCanvas::readPixels[2][3] SkSurface::readPixels[2][3]
Copies a Rect of pixels from Image to dst. Copy starts at (srcX, srcY), and does not exceed Image (width, height).
dst specifies width, height, Color Type, Alpha Type, Color Space, pixel storage, and row bytes of destination. dst.rowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:
Pixels are copied only if pixel conversion is possible. If Image Color Type is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType must match. If Image Color Type is kGray_8_SkColorType, dst.colorSpace must match. If Image Alpha Type is kOpaque_SkAlphaType, dst.alphaType must match. If Image Color Space is nullptr, dst.colorSpace must match. Returns false if pixel conversion is not possible.
srcX and srcY may be negative to copy only top or left of source. Returns false if width or height is zero or negative. Returns false ifabs(srcX) >= Image width, or ifabs(srcY) >= Image height.
If cachingHint is kAllow CachingHint, pixels may be retained locally. If cachingHint is kDisallow CachingHint, pixels are not added to the local cache.
true if pixels are copied to dst
scalePixels SkBitmap::readPixels[2][3][4] SkPixmap::readPixels[2][3][4][5] SkCanvas::readPixels[2][3] SkSurface::readPixels[2][3]
Copies Image to dst, scaling pixels to fit dst.width and dst.height, and converting pixels to match dst.colorType and dst.alphaType. Returns true if pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes is less than dst SkImageInfo::minRowBytes.
Pixels are copied only if pixel conversion is possible. If Image Color Type is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType must match. If Image Color Type is kGray_8_SkColorType, dst.colorSpace must match. If Image Alpha Type is kOpaque_SkAlphaType, dst.alphaType must match. If Image Color Space is nullptr, dst.colorSpace must match. Returns false if pixel conversion is not possible.
Scales the image, with filterQuality, to match dst.width and dst.height. filterQuality kNone_SkFilterQuality is fastest, typically implemented with Filter Quality Nearest Neighbor. kLow_SkFilterQuality is typically implemented with Filter Quality Bilerp. kMedium_SkFilterQuality is typically implemented with Filter Quality Bilerp, and Filter Quality MipMap when size is reduced. kHigh_SkFilterQuality is slowest, typically implemented with Filter Quality BiCubic.
If cachingHint is kAllow CachingHint, pixels may be retained locally. If cachingHint is kDisallow CachingHint, pixels are not added to the local cache.
true if pixels are scaled to fit dst
SkCanvas::drawImage[2] readPixels[2] SkPixmap::scalePixels
Encodes Image pixels, returning result as SkData.
Returns nullptr if encoding fails, or if encodedImageFormat is not supported.
Image encoding in a format requires both building with one or more of: SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY; and platform support for the encoded format.
If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can additionally be one of: SkEncodedImageFormat::kICO, SkEncodedImageFormat::kBMP, SkEncodedImageFormat::kGIF.
quality is a platform and format specific metric trading off size and encoding error. When used, quality equaling 100 encodes with the least error. quality may be ignored by the encoder.
encoded Image, or nullptr
refEncodedData MakeFromEncoded
Encodes Image pixels, returning result as SkData. Returns existing encoded data if present; otherwise, Image is encoded with SkEncodedImageFormat::kPNG. Skia must be built with SK_HAS_PNG_LIBRARY to encode Image.
Returns nullptr if existing encoded data is missing or invalid, and encoding fails.
encoded Image, or nullptr
refEncodedData MakeFromEncoded
Returns encoded Image pixels as SkData, if Image was created from supported encoded stream format. Platform support for formats vary and may require building with one or more of: SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY.
Returns nullptr if Image contents are not encoded.
encoded Image, or nullptr
encodeToData[2] MakeFromEncoded
Returns subset of Image. subset must be fully contained by Image dimensions. The implementation may share pixels, or may copy them.
Returns nullptr if subset is empty, or subset is not contained by bounds, or pixels in Image could not be read or copied.
partial or full Image, or nullptr
MakeFromEncoded
Returns Image backed by GPU Texture associated with context. Returned Image is compatible with Surface created with dstColorSpace. The returned Image respects mipMapped setting; if mipMapped equals GrMipMapped::kYes, the backing texture allocates Mip Map levels. Returns original Image if context and dstColorSpace match and mipMapped is compatible with backing GPU Texture.
Returns nullptr if context is nullptr, or if Image was created with another GrContext.
created Image, or nullptr
MakeFromTexture[2]
Returns Raster Image or Lazy Image. Copies Image backed by GPU Texture into CPU memory if needed. Returns original Image if decoded in Raster Bitmap, or if encoded in a stream.
Returns nullptr if backed by GPU Texture and copy fails.
Raster Image, Lazy Image, or nullptr
makeTextureImage makeRasterImage MakeBackendTextureFromSkImage
Returns Raster Image. Copies Image backed by GPU Texture into CPU memory, or decodes Image from Lazy Image. Returns original Image if decoded in Raster Bitmap.
Returns nullptr if copy, decode, or pixel read fails.
Raster Image, or nullptr
isTextureBacked isLazyGenerated MakeFromRaster
Creates filtered Image. filter processes original Image, potentially changing color, position, and size. subset is the bounds of original Image processed by filter. clipBounds is the expected bounds of the filtered Image. outSubset is required storage for the actual bounds of the filtered Image. offset is required storage for translation of returned Image.
Returns nullptr if Image could not be created. If nullptr is returned, outSubset and offset are undefined.
Useful for animation of SkImageFilter that varies size from frame to frame. Returned Image is created larger than required by filter so that GPU Texture can be reused with different sized effects. outSubset describes the valid bounds of GPU Texture returned. offset translates the returned Image to keep subsequent animation frames aligned with respect to each other.
filtered Image, or nullptr
makeShader[2] SkPaint::setImageFilter
BackendTextureReleaseProc
Defines a callback function, taking one parameter of type GrBackendTexture with no return value. Function is called when back-end texture is to be released.
Creates a GrBackendTexture from the provided SkImage. Returns true and stores result in backendTexture and backendTextureReleaseProc if texture is created; otherwise, returns false and leaves backendTexture and backendTextureReleaseProc unmodified.
Call backendTextureReleaseProc after deleting backendTexture. backendTextureReleaseProc cleans up auxiliary data related to returned backendTexture. The caller must delete returned backendTexture after use.
If Image is both texture backed and singly referenced, image is returned in backendTexture without conversion or making a copy. Image is singly referenced if its was transferred solely using std::move().
If Image is not texture backed, returns texture with Image contents.
true if back-end texture was created
MakeFromTexture[2] makeTextureImage
Deprecated.
soon
Creates raster Bitmap with same pixels as Image. If legacyBitmapMode is kRO LegacyBitmapMode, returned bitmap is read-only and immutable. Returns true if Bitmap is stored in bitmap. Returns false and resets bitmap if Bitmap write did not succeed.
true if Bitmap was created
MakeRasterData makeRasterImage makeNonTextureImage
Returns true if Image is backed by an image-generator or other service that creates and caches its pixels or texture on-demand.
true if Image is created as needed
isTextureBacked MakeNonTextureImage
Creates Image in target Color Space. Returns nullptr if Image could not be created.
Returns original Image if it is in target Color Space. Otherwise, converts pixels from Image Color Space to target Color Space. If Image colorSpace returns nullptr, Image Color Space is assumed to be sRGB.
SkTransferFunctionBehavior is to be deprecated.
Set premulBehavior to SkTransferFunctionBehavior::kRespect to convert Image pixels to a linear space, before converting to destination Color Type and Color Space.
Set premulBehavior to SkTransferFunctionBehavior::kIgnore to treat Image pixels as linear, when converting to destination Color Type and Color Space, ignoring pixel encoding. premulBehavior is SkTransferFunctionBehavior::kIgnore by default.
created Image in target Color Space
MakeFromPixture MakeFromTexture[2]