WriteableBitmap Constructor (BitmapSource)

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

Initializes a new instance of the WriteableBitmap class using the provided BitmapSource.

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Sub New ( _
    source As BitmapSource _
)
[SecuritySafeCriticalAttribute]
public WriteableBitmap(
    BitmapSource source
)

Parameters

Remarks

If source does not use a natively supported bitmap format, format conversions are applied for each frame update, which reduces performance.

If you use a BitmapImage as the source, remember that a BitmapImage constructed by a URL is initialized asynchronously. The default mode in Silverlight is DelayCreation, and in this case the image is possibly not being added to the visual tree and is thus not immediately requested for download. As such the image may be null and throws an exception in the constructor. It may be necessary to construct the image separately (using IgnoreImageCache), attach a handler for ImageOpened for the source, and only construct the WriteableBitmap once the ImageOpened event is handled.

Version Notes

Silverlight for Windows Phone Silverlight for Windows Phone

When you specify a BitmapImage as the parameter for the WriteableBitmap constructor, you must set the CreateOptions property of the BitmapImage before you use it to construct the WriteableBitmap; otherwise, an exception will occur.

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.