ARTICLE

Fill a shape with image in WPF Application

Posted by Sapna Articles | WPF using VB.NET September 30, 2010
With the help of this article you can fill a shape with any image in WPF Application.
 
Reader Level:

Suppose you want to fill a shape with an image in WpfApplication. Draw an image to your window with the help of toolbox as you see in the following example we draw an ellipse and now want fill it with an image, lets see the following code to do that:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="400" Width="400">
    <Canvas Margin="5">
        <!--Define a static ImageBrush resource-->
        <Canvas.Resources>
            <ImageBrush x:Key="IB1" ImageSource="c:\flower.jpg" />
        </Canvas.Resources>
 
        <!--Fill ellipse using static ImageBrush resource-->
        <Ellipse Height="260" Width="260"  Canvas.Top="20" Canvas.Left="50"
                 Stroke="Black" StrokeThickness="1"
                 Fill="{StaticResource IB1}" />
    </Canvas>
</
Window>

OUTPUT

shape.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor