Freigeben über


WriteableBitmap Constructor (UIElement, Transform)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Sub New ( _
    element As UIElement, _
    transform As Transform _
)
[SecuritySafeCriticalAttribute]
public WriteableBitmap(
    UIElement element,
    Transform transform
)

Parameters

  • 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 nulla null reference (Nothing in Visual Basic).

Exceptions

Exception Condition
ArgumentNullException

element is null.

ArgumentException

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

Remarks

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.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

Platforms

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