Click here to Skip to main content
15,886,776 members
Articles / Desktop Programming / WPF

Convert XAML Vector Graphic to PNG

Rate me:
Please Sign up or sign in to vote.
4.87/5 (11 votes)
23 Oct 2012CPOL12 min read 74.3K   6.8K   43  
An introduction to the usage of vector graphics as a source of bitmap graphics.
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Canvas.Background>  <DrawingBrush><DrawingBrush.Drawing><DrawingGroup>
  <DrawingGroup x:Name="DrawingLayer">
    <DrawingGroup.ClipGeometry>
      <RectangleGeometry Rect="0,0,507.946,507.946" />
    </DrawingGroup.ClipGeometry>
    <GeometryDrawing x:Name="path52">
      <GeometryDrawing.Pen>
        <Pen Thickness="5.89395" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Round">
          <Pen.Brush>
            <SolidColorBrush Color="#FFA4C9EE" Opacity="0.916084" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="-2.89921,2.66846,2.80481,3.04735,266.591,-101.582" Figures="M48.0514,64.9283L65.8735,83.7475 14,84 14.6122,31.0877 29.9596,47.1139C35.8422,41.7351 39.0476,38.9067 43.323,35.1913 49.346,30.9973 60.7087,21.8821 76.7008,19.262 89.6532,20.3554 93.7025,20.1741 102.405,25.2389 110.682,30.3037 115.745,35.6084 120.299,45.738 121.873,53.3899 122,60 121,68 117.297,84.6495 110.256,92.6963 100,100 91.9055,105.834 83.0793,107.864 67.6122,108.418 61.7755,106.089 58.3878,104.835 60.1633,102.505 66.8368,101.34 76.0944,98.5059 86.2913,93.6231 102.599,80.5946 108.469,60.128 99.1771,51.1065 90.1845,41.823 75.5186,40.1927 60.0931,53.6223 54.37,59.0353 54.9027,59.1024 48.0514,64.9283z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <GeometryDrawing x:Name="path266">
      <GeometryDrawing.Brush>
        <LinearGradientBrush StartPoint="-0.306693,-0.0175583" EndPoint="1.1202,0.724274" MappingMode="RelativeToBoundingBox" SpreadMethod="Pad" Opacity="1">
          <LinearGradientBrush.Transform>
            <TransformGroup>
              <MatrixTransform>0.921888,0,0,1.08473,0.222334,0.144046</MatrixTransform>
              <MatrixTransform>-2.80011,2.57725,2.65634,2.88604,265.825,-85.3814</MatrixTransform>
            </TransformGroup>
          </LinearGradientBrush.Transform>
          <GradientStop Color="#FF73FFFF" Offset="0" />
          <GradientStop Color="#FF2EA6B9" Offset="0.2809" />
          <GradientStop Color="#FF006B8B" Offset="1" />
        </LinearGradientBrush>
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="4" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter">
          <Pen.Brush>
            <SolidColorBrush Color="#FF0C6671" Opacity="0.988235" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="-2.80011,2.57725,2.65634,2.88604,265.825,-85.3814" Figures="M44.4256,65L62,84 14,84 14,34 28,50C34.6997,43.1341 38.4051,39.9761 43,36 47,32 64,19 77,19 90,19 101.486,21.755 112.599,33.7201 123.998,45.9875 122,60 121,68 117.872,84.6722 111.393,91.1547 102.69,99.819 93.7008,108.183 80.0426,110.712 67.5456,110.178 63.5456,110.178 59,106 62,106 74.3572,103.196 83.1707,99.5866 91.6497,92.831 106.944,77.6841 108.126,58.8717 99.525,49.6516 90.6386,40.1309 73.3605,39.11 58.2564,52.4574 51.9384,57.8465 51.2769,59.1741 44.4256,65z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
  </DrawingGroup>
      </DrawingGroup></DrawingBrush.Drawing></DrawingBrush></Canvas.Background></Canvas>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
The Windows Presentation Foundation (WPF) and C# are among my favorites and so I developed Edi

and a few other projects on GitHub. I am normally an algorithms and structure type but WPF has such interesting UI sides that I cannot help myself but get into it.

https://de.linkedin.com/in/dirkbahle

Comments and Discussions