Click here to Skip to main content
15,878,809 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.2K   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.39205,0,0,1.40472,-162.066,-173.376" />
      </GeometryDrawing.Brush>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="1.39205,0,0,1.40472,-162.066,-173.376" 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>
    <GeometryDrawing x:Name="path200">
      <GeometryDrawing.Pen>
        <Pen Brush="#FF000000" Thickness="1.25" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter" />
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="EvenOdd" Transform="1,0,0,1,411.805,-4.80701" Figures="M314.862,103.352L316.465,106.557" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <GeometryDrawing x:Name="path1001">
      <GeometryDrawing.Brush>
        <RadialGradientBrush Center="6.45111,1.77847" RadiusX="0.680479" RadiusY="0.680479" GradientOrigin="6.45111,1.77847" MappingMode="RelativeToBoundingBox" SpreadMethod="Pad" Opacity="1" Transform="1.08053,0,0,0.925469,0.24371,0.671872">
          <GradientStop Color="#FFC7EDF7" Offset="0" />
          <GradientStop Color="#FF3E9EA6" Offset="1" />
        </RadialGradientBrush>
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="11.905" StartLineCap="Round" EndLineCap="Round" LineJoin="Round">
          <Pen.Brush>
            <SolidColorBrush Color="#FF1C6671" Opacity="0.988235" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="EvenOdd" Figures="M265.189,328.215L225.131,287.622C225.131,285.128 215.334,294.032 212.312,294.032 197.357,311.451 170.009,312.191 148.218,310.055 128.43,306.85 111.013,294.75 103.352,286.02 88.7008,270.301 78.7823,256.987 71.3047,232.074 69.1682,215.585 72.0023,189.879 83.0554,180.265 90.533,170.151 96.1371,167.709 109.227,169.048 116.509,173.321 123.114,179.77 128.455,184.003L161.037,216.585C167.446,223.218,176.215,228.113,180.265,224.063L228.336,175.457C228.336,172.947,221.393,165.433,217.12,161.036L186.141,130.591C169.049,110.868 169.582,108.544 172.787,96.4082 177.06,88.2653 183.028,77.714 190.948,75.5776 203.293,68.5724 225.437,66.4976 242.222,72.907 257.425,78.4956 274.008,90.2714 283.349,99.6125 293.033,112.501 303.646,124.489 310.055,143.411 315.397,187.876 297.816,196.288 290.293,211.243 284.952,217.354 281.447,221.392 280.145,234.211L318.601,270.531C318.601,274.115,264.655,328.215,265.189,328.215z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <GeometryDrawing x:Name="path354">
      <GeometryDrawing.Brush>
        <LinearGradientBrush StartPoint="0.971959,0.492186" EndPoint="0.0373832,0.507812" MappingMode="RelativeToBoundingBox" SpreadMethod="Pad" Opacity="1">
          <LinearGradientBrush.Transform>
            <TransformGroup>
              <MatrixTransform>0.999999,0,0,1,2.49454E-08,7.55061E-08</MatrixTransform>
              <MatrixTransform>0.684536,-0.728979,0.792138,0.743845,-206.578,414.282</MatrixTransform>
            </TransformGroup>
          </LinearGradientBrush.Transform>
          <GradientStop Color="#FFFBDDB2" Offset="0" />
          <GradientStop Color="#FFEFA81A" Offset="1" />
        </LinearGradientBrush>
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="13.3239" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Round">
          <Pen.Brush>
            <SolidColorBrush Color="#FFCF5D07" Opacity="0.992157" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="EvenOdd" Transform="0.684536,-0.728979,0.792138,0.743845,-206.578,414.282" Figures="M387.834,258.217L387.834,465.72C387.942,473.804 391.61,479.266 398.84,480.141 416.396,480.141 433.952,480.141 451.508,480.141 457.956,478.49 462.266,473.561 462.304,467.322L463.906,258.217 387.834,258.217z" />
      </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