Getting Pixel Data

BitmapDecoder exposes a GetPixelDataAsync method that ultimately gives you a raw byte array with the image’s pixel data flattened into one dimension. However, this is done via an intermediate PixelDataProvider class as follows:

async Task UseDecoder(BitmapDecoder decoder) {   PixelDataProvider provider = await decoder.GetPixelDataAsync();   byte[] pixels = provider.DetachPixelData();   ... }

DetachPixelData can be called only once per PixelDataProvider instance, because it does not hold onto a copy of the bytes. (PixelDataProvider exists solely because of a limitation with the projection mechanism for Windows Runtime APIs: asynchronous methods cannot return arrays!)

BitmapDecoder has PixelWidth ...

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.