SKBitmap Class

Definition

The SKBitmap specifies a raster bitmap.

public class SKBitmap : SkiaSharp.SKObject
Inheritance

Remarks

A bitmap has an integer width and height, and a format (color type), and a pointer to the actual pixels. Bitmaps can be drawn into a SKCanvas, but they are also used to specify the target of a SKCanvas' drawing operations.

A SKBitmap exposes GetPixels(), which lets a caller write its pixels. To retrieve a pointer to the raw image data of the bitmap, call the SkiaSharp.SKBitmap.LockPixels method, and then call the GetPixels() method to get a pointer to the image data. Once you no longer need to use the raw data pointer, call the SkiaSharp.SKBitmap.UnlockPixels method. The raw data is laid out in the format configured at the time that the bitmap was created.

(Note: As of SkiaSharp 1.60.0, calls to SkiaSharp.SKBitmap.LockPixels and SkiaSharp.SKBitmap.UnlockPixels are no longer required, and they no longer exist as part of the API.)

Constructors

SKBitmap()

Default constructor that creates a bitmap with zero width and height, and no pixels. Its color type is set to Unknown.

SKBitmap(Int32, Int32, Boolean)

Creates a bitmap with the given width, height and opacity with color type set to PlatformColorType

SKBitmap(Int32, Int32, SKColorType, SKAlphaType)

Creates a bitmap with the given width, height, color type and alpha type.

SKBitmap(Int32, Int32, SKColorType, SKAlphaType, SKColorSpace)
SKBitmap(SKImageInfo)

Constructor that configures the bitmap based on an SKImageInfo specification.

SKBitmap(SKImageInfo, Int32)

Constructor that configures the bitmap based on an SKImageInfo specification, and the specified number of bytes per row (the stride size)

SKBitmap(SKImageInfo, SKBitmapAllocFlags)

Constructor that configures the bitmap based on an SKImageInfo specification.

SKBitmap(SKImageInfo, SKColorTable)
Obsolete.

Constructor that configures the bitmap based on an SKImageInfo specification and a color table.

SKBitmap(SKImageInfo, SKColorTable, SKBitmapAllocFlags)
Obsolete.

Constructor that configures the bitmap based on an SKImageInfo specification and a color table.

Properties

AlphaType

Gets the configured SKAlphaType for the bitmap.

ByteCount

Returns the byte size of the pixels, based on the Height and RowBytes.

Bytes

Gets a copy of all the pixel data as a byte array.

BytesPerPixel

Gets the number of bytes used per pixel.

ColorSpace

Gets the color space of the bitmap.

ColorTable
Obsolete.

Gets the color table of the bitmap.

ColorType

Gets the color type of the bitmap.

DrawsNothing

Gets a value indicating whether drawing this bitmap has any effect.

Handle

Gets or sets the handle to the underlying native object.

(Inherited from SKObject)
Height

Gets the height of the bitmap.

IgnorePublicDispose

Gets or sets a value indicating whether the call the public Dispose() should be no-op.

(Inherited from SKNativeObject)
Info

Gets an instance of SKImageInfo with all the properties of the bitmap.

IsDisposed

Gets or sets a value indicating whether the object has already been disposed.

(Inherited from SKNativeObject)
IsEmpty

Gets a value indicating whether the bitmap has empty dimensions.

IsImmutable

Indicates if the bitmap contents are immutable.

IsNull

Gets a value indicating whether the bitmap has any pixelref.

IsVolatile
Obsolete.

Gets a value indicating whether the bitmap should not be cached by devices.

OwnsHandle

Gets a value indicating whether this object should destroy the underlying native object.

(Inherited from SKObject)
Pixels

Gets all the pixels as an array of colors.

ReadyToDraw

Gets a value indicating whether or not the bitmap is valid enough to be drawn.

RowBytes

The number of bytes per row.

Width

Gets the width of the bitmap.

Methods

CanCopyTo(SKColorType)

Returns true if this bitmap's pixels can be converted into the requested color type, such that Copy() or CopyTo(SKBitmap) could succeed.

Copy()

Copies the contents of the bitmap and returns the copy.

Copy(SKColorType)

Copies the contents of the bitmap with the specified color type and returns the copy.

CopyTo(SKBitmap)

Copies the contents of the bitmap into the specified bitmap.

CopyTo(SKBitmap, SKColorType)

Copies the contents of the bitmap into the specified bitmap.

Decode(Byte[])

Decode a bitmap using the specified byte buffer.

Decode(Byte[], SKImageInfo)

Decode a bitmap using the specified byte buffer and destination image information.

Decode(ReadOnlySpan<Byte>)
Decode(ReadOnlySpan<Byte>, SKImageInfo)
Decode(SKCodec)

Decode a bitmap using the specified codec.

Decode(SKCodec, SKImageInfo)

Decode a bitmap using the specified codec and destination image information.

Decode(SKData)

Decode a bitmap using the specified data.

Decode(SKData, SKImageInfo)

Decode a bitmap using the specified data and destination image information.

Decode(SKStream)

Decode a bitmap using the specified stream.

Decode(SKStream, SKImageInfo)

Decode a bitmap using the specified stream and destination image information.

Decode(Stream)

Decode a bitmap using the specified stream and destination image information.

Decode(Stream, SKImageInfo)

Decode a bitmap using the specified stream and destination image information.

Decode(String)

Decode a bitmap for the specified filename.

Decode(String, SKImageInfo)

Decode a bitmap for the specified filename and destination image information.

DecodeBounds(Byte[])

Decode the bitmap information using the specified byte buffer.

DecodeBounds(ReadOnlySpan<Byte>)
DecodeBounds(SKData)

Decode the bitmap information using the specified data.

DecodeBounds(SKStream)

Decode the bitmap information using the specified stream.

DecodeBounds(Stream)

Decode the bitmap information using the specified stream.

DecodeBounds(String)

Decode the bitmap information for the specified filename.

Dispose()

Releases all resources used by this SKNativeObject.

(Inherited from SKNativeObject)
Dispose(Boolean)

Releases the unmanaged resources used by the SKBitmap and optionally releases the managed resources.

DisposeInternal()

Triggers a dispose, ignoring the value of IgnorePublicDispose.

(Inherited from SKNativeObject)
DisposeManaged()

Implemented by derived SKObject types to destroy any managed objects.

(Inherited from SKObject)
DisposeNative()

Implemented by derived SKObject types to destroy any native objects.

DisposeNative()

Implemented by derived SKObject types to destroy any native objects.

(Inherited from SKObject)
DisposeUnownedManaged() (Inherited from SKObject)
Encode(SKEncodedImageFormat, Int32)
Encode(SKWStream, SKEncodedImageFormat, Int32)
Obsolete.

Encodes the image using the specified format.

Encode(Stream, SKEncodedImageFormat, Int32)
Erase(SKColor)

Fill the entire bitmap with the specified color.

Erase(SKColor, SKRectI)

Fill the specified area of this bitmap with the specified color.

ExtractAlpha(SKBitmap)

Retrieve the alpha layer of this bitmap.

ExtractAlpha(SKBitmap, SKPaint)

Retrieve the alpha layer of this bitmap after applying the specified paint.

ExtractAlpha(SKBitmap, SKPaint, SKPointI)

Retrieve the alpha layer of this bitmap after applying the specified paint.

ExtractAlpha(SKBitmap, SKPointI)

Retrieve the alpha layer of this bitmap.

ExtractSubset(SKBitmap, SKRectI)

Retrieve a subset of this bitmap.

FromImage(SKImage)

Creates a new bitmap from a copy of the pixel data in the specified image.

GetAddr(Int32, Int32)
Obsolete.

Returns the address of the specified pixel.

GetAddr16(Int32, Int32)
Obsolete.

Returns the 16-bit value of the specified pixel.

GetAddr32(Int32, Int32)
Obsolete.

Returns the 32-bit value of the specified pixel.

GetAddr8(Int32, Int32)
Obsolete.

Returns the 8-bit value of the specified pixel.

GetAddress(Int32, Int32)
GetIndex8Color(Int32, Int32)
Obsolete.

Returns the color corresponding to the pixel specified by the coordinates for palette-based (color table) bitmaps.

GetPixel(Int32, Int32)

Returns the color for the pixel at the specified location.

GetPixels()

Returns the address of the pixels for this bitmap.

GetPixels(IntPtr)

Returns the address of the pixels for this bitmap.

GetPixelSpan()

Returns a span that wraps the pixel data.

InstallMaskPixels(SKMask)

Installs the specified mask's pixels into the bitmap.

InstallPixels(SKImageInfo, IntPtr)

Installs the specified pixels into the bitmap.

InstallPixels(SKImageInfo, IntPtr, Int32)

Installs the specified pixels into the bitmap.

InstallPixels(SKImageInfo, IntPtr, Int32, SKBitmapReleaseDelegate)

Installs the specified pixels into the bitmap.

InstallPixels(SKImageInfo, IntPtr, Int32, SKBitmapReleaseDelegate, Object)

Installs the specified pixels into the bitmap.

InstallPixels(SKImageInfo, IntPtr, Int32, SKColorTable)
Obsolete.

Installs the specified pixels into the bitmap.

InstallPixels(SKImageInfo, IntPtr, Int32, SKColorTable, SKBitmapReleaseDelegate, Object)
Obsolete.

Developers should not use this obsolete method.

InstallPixels(SKPixmap)

Installs the specified pixels into the bitmap.

NotifyPixelsChanged()

Indicates to consumers of the bitmap that the pixel data has changed.

PeekPixels()

Returns the pixels if they are available without having to lock the bitmap.

PeekPixels(SKPixmap)

Returns the pixmap of the bitmap.

Reset()

Reset the bitmap to its initial state.

Resize(SKBitmap, SKBitmap, SKBitmapResizeMethod)
Obsolete.

Resizes the provided bitmap using the specified resize method.

Resize(SKBitmap, SKBitmapResizeMethod)
Obsolete.

Resizes the current bitmap using the specified resize method.

Resize(SKImageInfo, SKBitmapResizeMethod)
Obsolete.

Resizes the current bitmap using the specified resize method.

Resize(SKImageInfo, SKFilterQuality)

Resizes the current bitmap using the specified quality filter.

Resize(SKSizeI, SKFilterQuality)
ScalePixels(SKBitmap, SKFilterQuality)

Copies this pixmap to the destination, scaling the pixels to fit the destination size and converting the pixels to match the color type and alpha type.

ScalePixels(SKPixmap, SKFilterQuality)

Copies this pixmap to the destination, scaling the pixels to fit the destination size and converting the pixels to match the color type and alpha type.

SetColorTable(SKColorTable)
Obsolete.

Replaces the current color table of the bitmap.

SetImmutable()

Marks the bitmap as immutable.

SetPixel(Int32, Int32, SKColor)

Sets the color of the pixel at a specified location.

SetPixels(IntPtr)

Replaces the current pixel address for the bitmap.

SetPixels(IntPtr, SKColorTable)
Obsolete.

Developers should not use this obsolete method.

ToShader()
ToShader(SKShaderTileMode, SKShaderTileMode)
ToShader(SKShaderTileMode, SKShaderTileMode, SKMatrix)
TryAllocPixels(SKImageInfo)

Allocates the memory for the bitmap using the specified image information.

TryAllocPixels(SKImageInfo, Int32)

Allocates the memory for the bitmap using the specified image information.

TryAllocPixels(SKImageInfo, SKBitmapAllocFlags)

Allocates the memory for the bitmap using the specified image information.

Applies to