New to Telerik UI for WinForms? Start a free 30-day trial

Wraps a mutable GDI+ bitmap for RichTextEditor image operations; pixel-buffer members expose raw locked bitmap bytes rather than normalized pixel values.

Definition

Namespace:Telerik.WinControls.RichTextEditor.UI

Assembly:Telerik.WinControls.RichTextEditor.dll

Syntax:

C#
public sealed class WriteableBitmap : BitmapSource

Inheritance: objectBitmapSourceWriteableBitmap

Constructors

Creates a bitmap copy from a WriteableBitmap or from a BitmapImage backed by a MemoryStream with a publicly accessible buffer.

C#
public WriteableBitmap(BitmapSource image)
Parameters:imageBitmapSource

The supported bitmap source to copy.

Other BitmapSource subtypes are not initialized by this overload.

Creates an independent bitmap copy from a GDI+ image.

C#
public WriteableBitmap(Image bitmapSource)
Parameters:bitmapSourceImage

The source image to copy.

Creates a bitmap with the specified dimensions and mapped pixel format.

C#
public WriteableBitmap(int width, int height, int dpiX, int dpiY, PixelFormat pixelFormat)
Parameters:widthint

The bitmap width in pixels.

heightint

The bitmap height in pixels.

dpiXint

Ignored; this implementation does not apply a horizontal resolution.

dpiYint

Ignored; this implementation does not apply a vertical resolution.

pixelFormatPixelFormat

The pixel format to map to GDI+; unrecognized values use 32-bit ARGB.

Creates an independent bitmap copy of another writable bitmap.

C#
public WriteableBitmap(WriteableBitmap writeableBitmap)
Parameters:writeableBitmapWriteableBitmap

The bitmap to copy.

Properties

Gets the mutable GDI+ bitmap held by this instance.

C#
public Bitmap Bitmap { get; }

Gets the palette entries captured when the backing bitmap was initialized.

C#
public Color[] Colors { get; }

The returned array is cached; changing it does not update the backing bitmap's palette.

Gets the compatibility pixel format mapped from the backing GDI+ format; unmapped formats report Bgra32.

C#
public PixelFormat Format { get; }

Gets the backing bitmap's height in pixels.

C#
public int PixelHeight { get; }

Pixels

IEnumerable<int>

Gets an eagerly created sequence containing one packed integer for each consecutive group of four raw bitmap bytes.

C#
public IEnumerable<int> Pixels { get; }

The sequence is a snapshot made when this property is read; the implementation does not normalize values for pixel format or row padding.

Gets the backing bitmap's width in pixels.

C#
public int PixelWidth { get; }

Methods

Copies raw bitmap bytes row by row into a byte array.

C#
public void CopyPixels(byte[] pixels, int stride, int offset)
Parameters:pixelsbyte[]

The destination byte array.

strideint

The number of bytes copied per row.

offsetint

The starting index in the destination array.

The source row advance uses the backing bitmap's GDI+ stride; bytes are not converted to another pixel format.

Fills the destination with values packed from consecutive groups of four raw bitmap bytes.

C#
public void CopyPixels(int[] pixels, int stride, int offset)
Parameters:pixelsint[]

The destination array of packed pixel values.

strideint

A legacy row-stride value used only while building an intermediate buffer.

offsetint

A legacy byte offset used only while building an intermediate buffer.

The final values are packed directly from consecutive source bytes, so the destination conversion does not apply stride or offset and does not normalize for the bitmap pixel format.

Attempts to write bytes from the supplied packed pixel values into the backing bitmap buffer.

C#
public void WritePixels(Rect rect, int[] pixels, int stride, int offset)
Parameters:rectRect

The requested destination rectangle; the current implementation ignores this value.

pixelsint[]

The source pixel values, read as raw bytes.

strideint

The number of bytes per destination row used to calculate bitmap-buffer coordinates.

offsetint

The starting index in the source buffer.

This implementation writes from the bitmap origin and does not convert pixel formats. It requests a read-only GDI+ lock before copying data back to the bitmap.