ImageDrawing Class
Draws an image within a region defined by a Rect.
Namespace: System.Windows.Media
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
The ImageDrawing type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ImageDrawing() | Initializes a new instance of the ImageDrawing class. |
![]() | ImageDrawing(ImageSource, Rect) | Initializes a new instance of the ImageDrawing class that has the specified target ImageSource and Rect. |
| Name | Description | |
|---|---|---|
![]() | Bounds | Gets the axis-aligned bounds of the drawing's contents. (Inherited from Drawing.) |
![]() | CanFreeze | Gets a value that indicates whether the object can be made unmodifiable. (Inherited from Freezable.) |
![]() | DependencyObjectType | Gets the DependencyObjectType that wraps the CLR type of this instance. (Inherited from DependencyObject.) |
![]() | Dispatcher | Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.) |
![]() | HasAnimatedProperties | Gets a value that indicates whether one or more AnimationClock objects is associated with any of this object's dependency properties. (Inherited from Animatable.) |
![]() | ImageSource | Gets or sets the source of the image |
![]() | IsFrozen | Gets a value that indicates whether the object is currently modifiable. (Inherited from Freezable.) |
![]() | IsSealed | Gets a value that indicates whether this instance is currently sealed (read-only). (Inherited from DependencyObject.) |
![]() | Rect | Gets or sets the region in which the image is drawn. |
| Name | Description | |
|---|---|---|
![]() | ApplyAnimationClock(DependencyProperty, AnimationClock) | Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the SnapshotAndReplace handoff behavior is used. (Inherited from Animatable.) |
![]() | ApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior) | Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the specified HandoffBehavior is used. (Inherited from Animatable.) |
![]() | BeginAnimation(DependencyProperty, AnimationTimeline) | Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the SnapshotAndReplace handoff behavior is used. (Inherited from Animatable.) |
![]() | BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior) | Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the specified HandoffBehavior is used. (Inherited from Animatable.) |
![]() | CheckAccess | Determines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.) |
![]() | ClearValue(DependencyProperty) | Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject.) |
![]() | ClearValue(DependencyPropertyKey) | Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject.) |
![]() | Clone | Creates a modifiable clone of this ImageDrawing, making deep copies of this object's values. When copying dependency properties, this method copies resource references and data bindings (but they might no longer resolve) but not animations or their current values. |
![]() | CloneCurrentValue | Creates a modifiable clone of this ImageDrawing object, making deep copies of this object's current values. Resource references, data bindings, and animations are not copied, but their current values are. |
![]() | CoerceValue | Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject. (Inherited from DependencyObject.) |
![]() | Equals | Determines whether a provided DependencyObject is equivalent to the current DependencyObject. (Inherited from DependencyObject.) |
![]() | Freeze() | Makes the current object unmodifiable and sets its IsFrozen property to true. (Inherited from Freezable.) |
![]() | GetAnimationBaseValue | Returns the non-animated value of the specified DependencyProperty. (Inherited from Animatable.) |
![]() | GetAsFrozen | Creates a frozen copy of the Freezable, using base (non-animated) property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.) |
![]() | GetCurrentValueAsFrozen | Creates a frozen copy of the Freezable using current property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.) |
![]() | GetHashCode | Gets a hash code for this DependencyObject. (Inherited from DependencyObject.) |
![]() | GetLocalValueEnumerator | Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetValue | Returns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject.) |
![]() | InvalidateProperty | Re-evaluates the effective value for the specified dependency property (Inherited from DependencyObject.) |
![]() | ReadLocalValue | Returns the local value of a dependency property, if it exists. (Inherited from DependencyObject.) |
![]() | SetCurrentValue | Sets the value of a dependency property without changing its value source. (Inherited from DependencyObject.) |
![]() | SetValue(DependencyProperty, Object) | Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject.) |
![]() | SetValue(DependencyPropertyKey, Object) | Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject.) |
![]() | ShouldSerializeProperty | Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property. (Inherited from DependencyObject.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | VerifyAccess | Enforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.) |
| Name | Description | |
|---|---|---|
![]() ![]() | ImageSourceProperty | Identifies the ImageSource dependency property. |
![]() ![]() | RectProperty | Identifies the Rect dependency property. |
Performance Note: A DrawingImage provides less features then an Image for rendering images, however, DrawingImage provides performance benefits making them ideal for describing backgrounds, clip art, and for low-level drawing with Visual objects. See Drawing Objects Overview for more information.
An ImageDrawing is a type of Freezable object and therefore can be frozen to improve performance. For information about Freezable features, such as freezing and cloning, see the Freezable Objects Overview.
This example shows how to use an ImageDrawing to draw an image. An ImageDrawing enables you display an ImageSource with a DrawingBrush, DrawingImage, or Visual. To draw an image, you create an ImageDrawing and set its ImageDrawing.ImageSource and ImageDrawing.Rect properties. The ImageDrawing.ImageSource property specifies the image to draw, and the ImageDrawing.Rect property specifies the position and size of each image.
The following example creates a composite drawing using four ImageDrawing objects. This example produces the following image:

using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Media.Imaging; namespace SDKSample { public class ImageDrawingExample : Page { public ImageDrawingExample() { // Create a DrawingGroup to combine the ImageDrawing objects. DrawingGroup imageDrawings = new DrawingGroup(); // Create a 100 by 100 image with an upper-left point of (75,75). ImageDrawing bigKiwi = new ImageDrawing(); bigKiwi.Rect = new Rect(75, 75, 100, 100); bigKiwi.ImageSource = new BitmapImage( new Uri(@"sampleImages\kiwi.png", UriKind.Relative)); imageDrawings.Children.Add(bigKiwi); // Create a 25 by 25 image with an upper-left point of (0,150). ImageDrawing smallKiwi1 = new ImageDrawing(); smallKiwi1.Rect = new Rect(0, 150, 25, 25); smallKiwi1.ImageSource = new BitmapImage(new Uri(@"sampleImages\kiwi.png", UriKind.Relative)); imageDrawings.Children.Add(smallKiwi1); // Create a 25 by 25 image with an upper-left point of (150,0). ImageDrawing smallKiwi2 = new ImageDrawing(); smallKiwi2.Rect = new Rect(150, 0, 25, 25); smallKiwi2.ImageSource = new BitmapImage(new Uri(@"sampleImages\kiwi.png", UriKind.Relative)); imageDrawings.Children.Add(smallKiwi2); // Create a 75 by 75 image with an upper-left point of (0,0). ImageDrawing wholeKiwi = new ImageDrawing(); wholeKiwi.Rect = new Rect(0, 0, 75, 75); wholeKiwi.ImageSource = new BitmapImage(new Uri(@"sampleImages\wholekiwi.png", UriKind.Relative)); imageDrawings.Children.Add(wholeKiwi); // // Use a DrawingImage and an Image control to // display the drawings. // DrawingImage drawingImageSource = new DrawingImage(imageDrawings); // Freeze the DrawingImage for performance benefits. drawingImageSource.Freeze(); Image imageControl = new Image(); imageControl.Stretch = Stretch.None; imageControl.Source = drawingImageSource; // Create a border to contain the Image control. Border imageBorder = new Border(); imageBorder.BorderBrush = Brushes.Gray; imageBorder.BorderThickness = new Thickness(1); imageBorder.HorizontalAlignment = HorizontalAlignment.Left; imageBorder.VerticalAlignment = VerticalAlignment.Top; imageBorder.Margin = new Thickness(20); imageBorder.Child = imageControl; this.Background = Brushes.White; this.Margin = new Thickness(20); this.Content = imageBorder; } } }
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="PresentationOptions" Background="White" Margin="20"> <Border BorderBrush="Gray" BorderThickness="1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20"> <Image Stretch="None"> <Image.Source> <DrawingImage PresentationOptions:Freeze="True"> <DrawingImage.Drawing> <DrawingGroup> <!-- The Rect property specifies that the image only fill a 100 by 100 rectangular area. --> <ImageDrawing Rect="75,75,100,100" ImageSource="sampleImages\kiwi.png"/> <!-- This image is set to fill a 25 by 25 rectangular area. --> <ImageDrawing Rect="0,150,25,25" ImageSource="sampleImages\kiwi.png"/> <!-- This image is set to fill a 25 by 25 rectangular area. --> <ImageDrawing Rect="150,0,25,25" ImageSource="sampleImages\kiwi.png"/> <!-- This image is set to fill a 75 by 75 rectangular area. --> <ImageDrawing Rect="0,0,75,75" ImageSource="sampleImages\wholekiwi.png"/> </DrawingGroup> </DrawingImage.Drawing> </DrawingImage> </Image.Source> </Image> </Border> </Page>
For an example showing a simple way to display an image without using ImageDrawing, see How to: Use the Image Element.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.





