Generating Dynamic Images with WriteableBitmap

WriteableBitmap, the other BitmapSource subclass, is designed for displaying dynamic pixel content. You construct an instance with a specific width and height, modify its pixels exposed via a PixelBuffer property, and set it as the Source of an Image element.

One common point of confusion is that PixelBuffer is a useless-looking Windows Runtime interface called IBuffer. IBuffer exposes only two properties: Capacity (the maximum number of bytes it can hold) and Length (the number of bytes currently in use).

C++ code can query the object for the IBufferByteAccess COM interface to read/write its data, but this is not an option for an app’s C# code. Instead, you can use the DataReader and DataWriter ...

Get XAML Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.