Table of Contents

Class WriteableBitmap

Namespace
Avalonia.Media.Imaging
Assembly
Avalonia.Base.dll

Holds a writeable bitmap image.

public class WriteableBitmap : Bitmap, IImage, IDisposable, IImageBrushSource
Inheritance
WriteableBitmap
Implements
Inherited Members

Constructors

WriteableBitmap(PixelSize, Vector, PixelFormat?, AlphaFormat?)

Initializes a new instance of the WriteableBitmap class.

public WriteableBitmap(PixelSize size, Vector dpi, PixelFormat? format = null, AlphaFormat? alphaFormat = null)

Parameters

size PixelSize

The size of the bitmap in device pixels.

dpi Vector

The DPI of the bitmap.

format PixelFormat?

The pixel format (optional).

alphaFormat AlphaFormat?

The alpha format (optional).

WriteableBitmap(PixelFormat, AlphaFormat, nint, PixelSize, Vector, int)

Initializes a new instance of the WriteableBitmap class with existing pixel data The data is copied to the bitmap

public WriteableBitmap(PixelFormat format, AlphaFormat alphaFormat, nint data, PixelSize size, Vector dpi, int stride)

Parameters

format PixelFormat

The pixel format.

alphaFormat AlphaFormat

The alpha format.

data nint

The pointer to the source bytes.

size PixelSize

The size of the bitmap in device pixels.

dpi Vector

The DPI of the bitmap.

stride int

The number of bytes per row.

Properties

Format

public override PixelFormat? Format { get; }

Property Value

PixelFormat?

Methods

CopyPixels(PixelRect, nint, int, int)

public override void CopyPixels(PixelRect sourceRect, nint buffer, int bufferSize, int stride)

Parameters

sourceRect PixelRect
buffer nint
bufferSize int
stride int

Decode(Stream)

public static WriteableBitmap Decode(Stream stream)

Parameters

stream Stream

Returns

WriteableBitmap

DecodeToHeight(Stream, int, BitmapInterpolationMode)

Loads a Bitmap from a stream and decodes at the desired height. Aspect ratio is maintained. This is more efficient than loading and then resizing.

public static WriteableBitmap DecodeToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)

Parameters

stream Stream

The stream to read the bitmap from. This can be any supported image format.

height int

The desired height of the resulting bitmap.

interpolationMode BitmapInterpolationMode

The BitmapInterpolationMode to use should any scaling be required.

Returns

WriteableBitmap

An instance of the WriteableBitmap class.

DecodeToWidth(Stream, int, BitmapInterpolationMode)

Loads a WriteableBitmap from a stream and decodes at the desired width. Aspect ratio is maintained. This is more efficient than loading and then resizing.

public static WriteableBitmap DecodeToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)

Parameters

stream Stream

The stream to read the bitmap from. This can be any supported image format.

width int

The desired width of the resulting bitmap.

interpolationMode BitmapInterpolationMode

The BitmapInterpolationMode to use should any scaling be required.

Returns

WriteableBitmap

An instance of the WriteableBitmap class.

Lock()

public ILockedFramebuffer Lock()

Returns

ILockedFramebuffer