CacheOption Property

BitmapImage.CacheOption Property


Gets or sets the BitmapCacheOption to use for this instance of BitmapImage.

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

public BitmapCacheOption CacheOption { get; set; }

Set the CacheOption to BitmapCacheOption.OnLoad if you wish to close a stream used to create the BitmapImage. The default OnDemand cache option retains access to the stream until the image is needed, and cleanup is handled by the garbage collector.

Identifier field


Metadata properties set to true


The following code example demonstrates how to set the CacheOption of a BitmapImage by using code.

' Define a BitmapImage.
Dim myImage As New Image()
Dim bi As New BitmapImage()

' Begin initialization.

' Set properties.
bi.CacheOption = BitmapCacheOption.OnDemand
bi.CreateOptions = BitmapCreateOptions.DelayCreation
bi.DecodePixelHeight = 125
bi.DecodePixelWidth = 125
bi.Rotation = Rotation.Rotate90
bi.UriSource = New Uri("smiley.png", UriKind.Relative)

' End initialization.
myImage.Source = bi
myImage.Stretch = Stretch.None
myImage.Margin = New Thickness(5)

.NET Framework
Available since 3.0
Return to top
© 2015 Microsoft