Click here to Skip to main content
15,891,607 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.4K   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="path51">
      <GeometryDrawing.Brush>
        <SolidColorBrush Color="#FFA4C9EE" Opacity="0.7" Transform="1.89511,0,0,1.91236,-231.458,-247.971" />
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="3.12678" 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="1.89511,0,0,1.91236,-231.458,-247.971" Figures="M134.757,263.776C134.757,330.515 189.055,384.816 255.796,384.816 322.535,384.816 376.835,330.515 376.835,263.776 376.835,197.035 322.535,142.737 255.796,142.737 189.055,142.737 134.757,197.035 134.757,263.776z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <DrawingGroup x:Name="g60">
      <GeometryDrawing x:Name="path52">
        <GeometryDrawing.Brush>
          <RadialGradientBrush Center="0.5,0.5" RadiusX="0.5" RadiusY="0.5" GradientOrigin="0.5,0.5" MappingMode="RelativeToBoundingBox" SpreadMethod="Pad" Opacity="0.701961">
            <RadialGradientBrush.Transform>
              <TransformGroup>
                <MatrixTransform>1,0,0,1,-2.46722E-09,1.0782E-08</MatrixTransform>
                <MatrixTransform>3.09442,0,0,3.25254,49.112,60.0875</MatrixTransform>
              </TransformGroup>
            </RadialGradientBrush.Transform>
            <GradientStop Color="#FF73FFFF" Offset="0" />
            <GradientStop Color="#FF2EA6B9" Offset="0.2809" />
            <GradientStop Color="#FF006B8B" Offset="1" />
          </RadialGradientBrush>
        </GeometryDrawing.Brush>
        <GeometryDrawing.Pen>
          <Pen Thickness="6.94311" 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="3.09442,0,0,3.25254,49.112,60.0875" Figures="M48.099,63.835L64.4489,83.4175 14,84 14.6122,31.0877 31.0612,48.2526C32.0612,49.2526 39,40 43,36 47,32 64,19 77,19 90,19 93.7025,20.1741 102.405,25.2389 110.682,30.3037 115.446,35.8704 120,46 121.574,53.6519 122,60 121,68 117.872,84.6722 110.256,92.6963 100,100 94,104 82.2531,107.01 67.6122,108.418 61.7755,106.089 58.3878,104.835 60.1633,102.505 66.8368,101.34 74,100.34 83,96.5052 97.2125,85.3108 103.163,78.7815 103.163,67 103.163,61 102.925,56.2343 99.7755,50.5825 95.7755,46.5825 92.6122,44.3517 81.6122,44.3517 70.6122,44.3517 67.0931,48.6223 60.0931,53.6223 54.37,59.0353 54.9503,58.0091 48.099,63.835z" />
        </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.98865,0,0,3.08037,58.1705,69.0411</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.98865,0,0,3.08037,58.1705,69.0411" Figures="M44.4256,65L62,84 62.4256,84 14,84 14,34 28,50C29,51 39,40 43,36 47,32 64,19 77,19 90,19 93.7025,20.1741 102.405,25.2389 110.682,30.3037 115.446,35.8704 120,46 121.574,53.6519 122,60 121,68 117.872,84.6722 110.256,92.6963 100,100 94,104 81.6409,108.174 67,109 63,109 59,106 62,106 65,106 74,105 83,100 99.6614,88.8056 105,78.7815 105,67 105,61 104.149,55.6518 101,50 97,46 92.6339,41.385 81.6339,41.385 70.6339,41.385 65.2564,47.4574 58.2564,52.4574 52.5333,57.8704 51.2769,59.1741 44.4256,65z" />
        </GeometryDrawing.Geometry>
      </GeometryDrawing>
    </DrawingGroup>
  </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