Click here to Skip to main content
15,880,427 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.89511,0,0,1.91236,-231.458,-247.971" />
      </GeometryDrawing.Brush>
      <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>
    <GeometryDrawing x:Name="path56">
      <GeometryDrawing.Brush>
        <RadialGradientBrush Center="218.9404,219.7715" RadiusX="150.7063" RadiusY="150.7063" GradientOrigin="218.9404,219.7715" MappingMode="Absolute" Opacity="1" Transform="2.04451,0,0,2.04451,-264.353,-281.723">
          <GradientStop Color="#FF73FFFF" Offset="0" />
          <GradientStop Color="#FF2EA6B9" Offset="0.2809" />
          <GradientStop Color="#FF006B8B" Offset="1" />
        </RadialGradientBrush>
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="7.73106" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter">
          <Pen.Brush>
            <SolidColorBrush Color="#FF1C6671" Opacity="0.988235" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="EvenOdd" Transform="2.04451,0,0,2.04451,-264.353,-281.723" Figures="M356.643,263.366C356.643,320.393 310.413,366.623 253.387,366.623 196.36,366.623 150.131,320.394 150.131,263.366 150.131,206.339 196.36,160.11 253.387,160.11 310.412,160.11 356.643,206.339 356.643,263.366z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <GeometryDrawing x:Name="path59">
      <GeometryDrawing.Brush>
        <SolidColorBrush Color="#FFFFFFFD" Opacity="0.7" Transform="1.39896,-1.41113,1.41113,1.39896,-469.673,250.645" />
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="4.99273" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter">
          <Pen.Brush>
            <SolidColorBrush Color="#FF1C6772" Opacity="0.988235" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="1.39896,-1.41113,1.41113,1.39896,-469.673,250.645" Figures="M305.753,281.376C305.753,281.376 286.895,262.52 277.899,253.525 285.842,245.581 299.051,232.372 299.051,232.372 300.964,230.459 301.98,227.901 301.98,225.299 301.98,224.01 301.731,222.711 301.218,221.474 299.67,217.738 296.025,215.301 291.98,215.301L215.117,215.301C209.594,215.301,205.117,219.778,205.117,225.301L205.117,302.168C205.117,306.213 207.554,309.859 211.29,311.407 215.027,312.955 219.329,312.098 222.188,309.238 222.188,309.238 235.396,296.027 243.34,288.083 252.336,297.079 271.192,315.937 271.192,315.937 273.067,317.813 275.611,318.867 278.263,318.867 280.915,318.867 283.458,317.813 285.334,315.938L305.754,295.518C307.629,293.642 308.683,291.099 308.683,288.447 308.683,285.795 307.629,283.251 305.753,281.376z" />
      </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