Represents a control that displays an image.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
The class enables you to load the following image types: .bmp, .gif, .ico, .jpg, .png, .wdp, and .tiff.
When displaying a multiframe image, only the first frame is displayed. The animation of multiframe images is not supported by the control.
This example shows how to include images in an application by using the element.
The following example shows how to render an image 200 pixels wide. In this Extensible Application Markup Language (XAML) example, both attribute syntax and property tag syntax are used to define the image. For more information on attribute syntax and property syntax, see Dependency Properties Overview. A BitmapImage is used to define the image's source data and is explicitly defined for the property tag syntax example. In addition, the DecodePixelWidth of the BitmapImage is set to the same width as the Width of the . This is done to ensure that the minimum amount of memory is used rendering the image.
In general, if you want to specify the size of a rendered image, specify only the Width or the Height but not both. If you only specify one, the image's aspect ratio is preserved. Otherwise, the image may unexpectedly appear stretched or warped. To control the image's stretching behavior, use the Stretch and StretchDirection properties.
<!-- Simple image rendering. However, rendering an image this way may not result in the best use of application memory. See markup below which creates the same end result but using less memory. --> <Image Width="200" Source="C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg"/> <Image Width="200"> <Image.Source> <!-- To save significant application memory, set the DecodePixelWidth or DecodePixelHeight of the BitmapImage value of the image source to the desired height and width of the rendered image. If you don't do this, the application will cache the image as though it were rendered as its normal size rather then just the size that is displayed. --> <!-- Note: In order to preserve aspect ratio, only set either DecodePixelWidth or DecodePixelHeight but not both. --> <BitmapImage DecodePixelWidth="200" UriSource="C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg" /> </Image.Source> </Image>
The following example shows how to render an image 200 pixels wide using code.
// Create Image Element Image myImage = new Image(); myImage.Width = 200; // Create source BitmapImage myBitmapImage = new BitmapImage(); // BitmapImage.UriSource must be in a BeginInit/EndInit block myBitmapImage.BeginInit(); myBitmapImage.UriSource = new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg"); // To save significant application memory, set the DecodePixelWidth or // DecodePixelHeight of the BitmapImage value of the image source to the desired // height or width of the rendered image. If you don't do this, the application will // cache the image as though it were rendered as its normal size rather then just // the size that is displayed. // Note: In order to preserve aspect ratio, set DecodePixelWidth // or DecodePixelHeight but not both. myBitmapImage.DecodePixelWidth = 200; myBitmapImage.EndInit(); //set image source myImage.Source = myBitmapImage;
|How to: Crop an Image||This example shows how to crop an image using CroppedBitmap.|
|How to: Rotate an Image||This example shows how to rotate an image 90 degrees by using a Rotation property of a BitmapImage.|
|How to: Convert an Image to Greyscale||This example shows how to convert an image to grayscale using FormatConvertedBitmap.|
|How to: Use a Drawing as an Image Source||This example shows how to use a Drawing as the Source for an control. To display a Drawing with an control, use a DrawingImage as the control's Source and set the DrawingImage object's DrawingImage.Drawing property to the drawing you want to display.|
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.