WriteableBitmap.PixelBuffer property
Gets an access for the direct buffer where each pixel of the WriteableBitmap is written to.
Syntax
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
|
Minimum supported client | Windows 8 |
|---|---|
|
Minimum supported server | Windows Server 2012 |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 12/4/2012
