Click here to Skip to main content
15,892,537 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,160,160" />
    </DrawingGroup.ClipGeometry>
    <GeometryDrawing x:Name="polygon3">
      <GeometryDrawing.Brush>
        <SolidColorBrush Color="#FF0C5D7D" Opacity="0.992157" Transform="0.797584,0,0,1.24992,56.2305,-2.71824" />
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="3.72423" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter">
          <Pen.Brush>
            <SolidColorBrush Color="#FF0C5D7D" Opacity="0.99" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="0.797584,0,0,1.24992,56.2305,-2.71824" Figures="M32.5,12L56.8988,34.5471 42.9771,34.8537 42.7252,61.5867 22.2748,61.5867 22.0229,34.8537 8.21868,35.1477 32.5,12z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <GeometryDrawing x:Name="path651">
      <GeometryDrawing.Brush>
        <SolidColorBrush Color="#FF0C5D7D" Opacity="0.992157" Transform="9.95215E-19,0.781212,-1.22426,1.55963E-18,171.015,60.3555" />
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="3.72423" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter">
          <Pen.Brush>
            <SolidColorBrush Color="#FF0C5D7D" Opacity="0.99" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="9.95215E-19,0.781212,-1.22426,1.55963E-18,171.015,60.3555" Figures="M32.5,12L56.8988,34.5471 42.9771,34.8537 42.0791,72.0798 21.6287,72.0798 22.0229,34.8537 8.21868,35.1477 32.5,12z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <GeometryDrawing x:Name="path652">
      <GeometryDrawing.Brush>
        <SolidColorBrush Color="#FF0C5D7D" Opacity="0.992157" Transform="-0.81341,2.07245E-18,-3.24781E-18,-1.27472,108.565,172.894" />
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="3.72423" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter">
          <Pen.Brush>
            <SolidColorBrush Color="#FF0C5D7D" Opacity="0.99" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="-0.81341,2.07245E-18,-3.24781E-18,-1.27472,108.565,172.894" Figures="M32.5,12L56.8988,34.5471 42.9771,34.8537 42.7252,61.018 22.2748,61.018 22.0229,34.8537 8.21868,35.1477 32.5,12z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <GeometryDrawing x:Name="path653">
      <GeometryDrawing.Brush>
        <SolidColorBrush Color="#FF0C5D7D" Opacity="0.992157" Transform="-3.07844E-18,-0.805497,1.26232,-4.82433E-18,-9.11143,111.473" />
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="3.72423" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter">
          <Pen.Brush>
            <SolidColorBrush Color="#FF0C5D7D" Opacity="0.99" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="-3.07844E-18,-0.805497,1.26232,-4.82433E-18,-9.11143,111.473" Figures="M32.5,12L56.8988,34.5471 42.9771,34.8537 42.7252,69.8962 22.2748,69.8962 22.0229,34.8537 8.21868,35.1477 32.5,12z" />
      </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