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 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 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 LockPixels() and 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(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)

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

SKBitmap(SKImageInfo, SKColorTable, SKBitmapAllocFlags)

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

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.

Info

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

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

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.

CopyPixelsTo(IntPtr, Int32, Int32, Boolean)

Copies the pixels of the bitmap to the specified memory location.

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(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(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.

Encode(SKWStream, SKEncodedImageFormat, Int32)

Encodes the image using the specified format.

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)

Returns the address of the specified pixel.

GetAddr16(Int32, Int32)

Returns the 16-bit value of the specified pixel.

GetAddr32(Int32, Int32)

Returns the 32-bit value of the specified pixel.

GetAddr8(Int32, Int32)

Returns the 8-bit value of the specified pixel.

GetIndex8Color(Int32, Int32)

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.

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)

Installs the specified pixels into the bitmap.

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

Developers should not use this obsolete method.

InstallPixels(SKPixmap)

Installs the specified pixels into the bitmap.

LockPixels()

Call this to ensure that the bitmap points to the current pixel address in the pixelref.

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)

Resizes the provided bitmap using the specified resize method.

Resize(SKBitmap, SKBitmapResizeMethod)

Resizes the current bitmap using the specified resize method.

Resize(SKImageInfo, SKBitmapResizeMethod)

Resizes the current bitmap using the specified resize method.

Resize(SKImageInfo, SKFilterQuality)

Resizes the current bitmap using the specified quality filter.

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)

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)

Developers should not use this obsolete method.

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.

UnlockPixels()

Call this to balance a previous call to LockPixels().

Applies to