Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
BitmapImage Class

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
BitmapImage Class

Provides a specialized BitmapSource that is optimized for loading images using Extensible Application Markup Language (XAML).

Namespace:  System.Windows.Media.Imaging
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/xaml/presentation
Visual Basic (Declaration)
Public NotInheritable Class BitmapImage _
    Inherits BitmapSource _
    Implements ISupportInitialize, IUriContext
Visual Basic (Usage)
Dim instance As BitmapImage
C#
public sealed class BitmapImage : BitmapSource, 
    ISupportInitialize, IUriContext
Visual C++
public ref class BitmapImage sealed : public BitmapSource, 
    ISupportInitialize, IUriContext
JScript
public final class BitmapImage extends BitmapSource implements ISupportInitialize, IUriContext
XAML Object Element Usage
<BitmapImage .../>

BitmapImage primarily exists to support Extensible Application Markup Language (XAML) syntax and introduces additional properties for bitmap loading that are not defined by BitmapSource.

BitmapImage implements the ISupportInitialize interface to optimize initialization on multiple properties. Property changes can only occur during object initialization. Call BeginInit to signal that initialization has begun and EndInit to signal that initialization has completed. After initialization, property changes are ignored.

BitmapImage objects created using the BitmapImage constructor are automatically initialized and property changes are ignored.

The following code examples demonstrate how to use a BitmapImage in Extensible Application Markup Language (XAML) and code.

<!-- Property Tag XAML Syntax -->
<Image Width="200"  Margin="5" Grid.Column="1" Grid.Row="1" >
   <Image.Source>
      <BitmapImage UriSource="sampleImages/bananas.jpg" />
   </Image.Source>
</Image>

<!-- Property Tag XAML Syntax -->
<Image Width="200"  Margin="5" Grid.Column="1" Grid.Row="1" >
   <Image.Source>
      <BitmapImage UriSource="sampleImages/bananas.jpg" />
   </Image.Source>
</Image>

Visual Basic
' Create the image element.
Dim simpleImage As New Image()
simpleImage.Width = 200
simpleImage.Margin = New Thickness(5)

' Create source.
Dim bi As New BitmapImage()
' BitmapImage.UriSource must be in a BeginInit/EndInit block.
bi.BeginInit()
bi.UriSource = New Uri("/sampleImages/cherries_larger.jpg", UriKind.RelativeOrAbsolute)
bi.EndInit()
' Set the image source.
simpleImage.Source = bi

C#
// Create the image element.
Image simpleImage = new Image();    
simpleImage.Width = 200;
simpleImage.Margin = new Thickness(5);

// Create source.
BitmapImage bi = new BitmapImage();
// BitmapImage.UriSource must be in a BeginInit/EndInit block.
bi.BeginInit();
bi.UriSource = new Uri(@"/sampleImages/cherries_larger.jpg",UriKind.RelativeOrAbsolute);
bi.EndInit();
// Set the image source.
simpleImage.Source = bi;

More Code

How to: Apply a Transform to a BitmapImage This example demonstrates how to apply a Transform to a BitmapImage.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Passing BitmapImage across threads      RandomEngy   |   Edit   |   Show History
If you need to load a BitmapImage in another thread, such as in a BackgroundWorker, you'll need to call Freeze() on it after EndInit(). This should also work if you want to do processing on an already existing BitmapImage in another thread.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker