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 12.4:
async Task UseEncoder(BitmapEncoder encoder) { const int PixelWidth = 1024; const int PixelHeight = 728; const int BytesPerPixel = ...
Get Universal Windows® Apps with XAML and C# 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.