How to fill a shape with an image in WPF

 
If you want to fill a shape with an image, suppose you have an ellipse on your form and you want to fill this ellipse with an image then you can use ImageBrush class that enable us to paint an area with an image. An ImageBrush paints an area with an ImageSource property. An ImageBrush is a type of TileBrush that defines its content as an image.

Example

In the following example we draw an ellipse and fill with an image:

<Window x:Class="SimpleStyles.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="SimpleStyles">
   <ScrollViewer Height="187" Width="600">
        <Grid Height="173" Name="Grid1" Width="581" ShowGridLines="False">
                <Ellipse Height="150" Width="150" HorizontalAlignment="Left" Margin="36,11,0,5">
                    <Ellipse.Fill>
                        <ImageBrush ImageSource="Images/Tulips1.jpg" />
                    </Ellipse.Fill>
                </Ellipse>
        </Grid>
      </ScrollViewer>  
  </Window>

Author: Hirendra Sisodiya

Programmer at PSPL. Can be found on Google Plus.