Windows Dev Center

WriteableBitmap Constructor (UIElement, Transform)

Initializes a new instance of the WriteableBitmap class using the provided element and transform.

Namespace:  System.Windows.Media.Imaging
Assembly:  System.Windows (in System.Windows.dll)

public WriteableBitmap(
	UIElement element,
	Transform transform
)

Parameters

element
Type: System.Windows.UIElement
The desired element to be rendered within the bitmap.
transform
Type: System.Windows.Media.Transform
The transform the user wants to apply to the element as the last step before drawing into the bitmap. This is particularly interesting for you if you want the bitmap to respect its transform. This value can be null.

ExceptionCondition
ArgumentNullException

element is null.

ArgumentException

The element size is invalid. This happens when the pixel width or pixel height is not greater than zero.

This constructor can be used to cover most "replicate content" scenarios by producing a WriteableBitmap that reduces white space and preserves content. This API will produce a PBGRA32 WriteableBitmap of the element. This WriteableBitmap takes into account many of the properties of child elements below the transform but not properties of parent elements. These properties include:

After rendering the element into an internal intermediate surface, the transform parameter is applied directly. This constructor allows for null to be supplied as the transform.

You may want the transform to be respected, in which case you can call:

WriteableBitmap wb = new WriteableBitmap(btn, btn.RenderTransform);

You may want the layout or perspective to be frozen into the WriteableBitmap, in this case, you can alter your visual tree to include a node above it. With this constructor, you have a way to create a bitmap with just the element, its subtree, and without the offset.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2015 Microsoft