O'Reilly logo

XAML Unleashed by Adam Nathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing Pixel Data

BitmapEncoder exposes a SetPixelData method that is analogous to the more complex overload of BitmapDecoder’s GetPixelDataAsync method. In addition to passing a flattened byte array (with pixels in row-major order), you must specify everything needed for the encoder to interpret the array: the pixel format, alpha mode, width, and height. You must also provide DPI values for both dimensions (or 0 to omit that metadata). The following implementation of UseEncoder creates a red-blue gradient image exactly like the one created with WriteableBitmap in Figure 11.4:

async Task UseEncoder(BitmapEncoder encoder){  const int PixelWidth = 1024;  const int PixelHeight = 728;  const int BytesPerPixel = 4;

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required