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


Type: System.Windows.UIElement
The desired element to be rendered within the bitmap.
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.


element is null.


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.


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.