--- title: "How to: Paint an Area with an Image" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "images [WPF], painting with" - "painting [WPF], with images" - "brushes [WPF], painting with images" ms.assetid: 3432c533-1fc7-492d-94ee-0b13d60125ae --- # How to: Paint an Area with an Image This example shows how to use the class to paint an area with an image. An displays a single image, which is specified by its property. ## Example The following example paints the of a button by using an . [!code-csharp[UsingImageBrush_snip#ImageBrushExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/UsingImageBrush_snip/CSharp/PaintingWithImagesExample.cs#imagebrushexamplewholepage)] By default, an stretches its image to completely fill the area that you are painting. In the preceding example, the image is stretched to fill the button, possibly distorting the image. You can control this behavior by setting the property of to or , which causes the brush to preserve the aspect ratio of the image. If you set the and properties of an , you can create a repeating pattern. The following example paints a button by using a pattern that is created from an image. [!code-csharp[UsingImageBrush_snip#TiledImageBrushExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/UsingImageBrush_snip/CSharp/TiledImageBrushExample.cs#tiledimagebrushexamplewholepage)] [!code-vb[UsingImageBrush_snip#TiledImageBrushExampleWholePage](~/samples/snippets/visualbasic/VS_Snippets_Wpf/UsingImageBrush_snip/VisualBasic/TiledImageBrushExample.vb#tiledimagebrushexamplewholepage)] For more information about the class, see [Painting with Images, Drawings, and Visuals](painting-with-images-drawings-and-visuals.md). This code example is part of a larger example that is provided for the class. For the complete sample, see [ImageBrush Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Graphics/ImageBrush). ## See also - [Painting with Images, Drawings, and Visuals](painting-with-images-drawings-and-visuals.md)