PixelBuffer property
Collapse the table of content
Expand the table of content

WriteableBitmap.PixelBuffer property

Gets an access for the direct buffer where each pixel of the WriteableBitmap is written to.

Syntax


Public ReadOnly Property PixelBuffer As IBuffer

Property value

Type: IBuffer

A reference to the pixel buffer.

Remarks

PixelBuffer cannot be written to directly, however, you can use language-specific techniques to access the buffer and change its contents.

  • To access the pixel content from C# or Microsoft Visual Basic, you can use the AsStream extension method to access the underlying buffer as a stream.
  • To access the pixel content from C++, you can query for the IBufferByteAccess type (defined in Robuffer.h) and directly access its Buffer property.

Examples

This example writes to the PixelBuffer property of WriteableBitmap as part of a transcoding scenario that will eventually use the WriteableBitmap as an Image.Source value and display the image. The code shown here comes from a larger code sample, the SDK XAML images sample.


using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) 
{
    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream); 
    // Scale image to appropriate size 
    BitmapTransform transform = new BitmapTransform() {  
        ScaledWidth = Convert.ToUInt32(Scenario4WriteableBitmap.PixelWidth), 
        ScaledHeight = Convert.ToUInt32(Scenario4WriteableBitmap.PixelHeight)
    }; 
    PixelDataProvider pixelData = await decoder.GetPixelDataAsync( 
        BitmapPixelFormat.Bgra8, // WriteableBitmap uses BGRA format 
        BitmapAlphaMode.Straight, 
        transform, 
        ExifOrientationMode.IgnoreExifOrientation, // This sample ignores Exif orientation 
        ColorManagementMode.DoNotColorManage
    ); 
 
    // An array containing the decoded image data, which could be modified before being displayed 
    byte[] sourcePixels = pixelData.DetachPixelData(); 
 
    // Open a stream to copy the image contents to the WriteableBitmap's pixel buffer 
    using (Stream stream = Scenario4WriteableBitmap.PixelBuffer.AsStream()) 
    { 
        await stream.WriteAsync(sourcePixels, 0, sourcePixels.Length); 
    }                     
}

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.UI.Xaml.Media.Imaging
Windows::UI::Xaml::Media::Imaging [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Media.Imaging
Windows::UI::Xaml::Media::Imaging [C++]

Metadata

Windows.winmd

See also

WriteableBitmap
BitmapSource
BitmapDecoder
Windows.Graphics.Imaging namespace
XAML images sample

 

 

Show:
© 2016 Microsoft