RenderTargetBitmap.GetPixelsAsync Method


Retrieves the previously rendered RenderTargetBitmap image as a buffered stream of bytes in BGRA8 format.

 virtual IAsyncOperation<IBuffer ^> ^ GetPixelsAsync() = GetPixelsAsync;
IAsyncOperation<IBuffer> GetPixelsAsync();
public IAsyncOperation<IBuffer> GetPixelsAsync();
function getPixelsAsync()
Public Function GetPixelsAsync () As IAsyncOperation(Of IBuffer)



When this method returns, an IBuffer stream that contains bytes. This is the binary data for the image and can be converted to a byte array in BGRA8 format



The IBuffer return value enables passing the result to a WriteableBitmap and its PixelBuffer. Another alternative is passing the buffer to a BitmapEncoder. If you want an array of bytes, use a DataReader and the FromBuffer method to help with the conversion.

Through the IAsyncOperation intermediate value, this method returns the pixels of the image source that was produced by the most recent call to RenderAsync.

Always call RenderAsync before calling GetPixelsAsync. If you call GetPixelsAsync and never called RenderAsync previously on that RenderTargetBitmap instance, GetPixelsAsync will return an empty buffer stream, and no error will occur (async Status is Completed, so you can't use that as an indicator).

Applies to

See also