Click here to Skip to main content
15,892,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.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="path266">
      <GeometryDrawing.Brush>
        <LinearGradientBrush StartPoint="-0.01654,-0.546712" EndPoint="0.0148676,0.138341" MappingMode="RelativeToBoundingBox" SpreadMethod="Pad" Opacity="1">
          <LinearGradientBrush.Transform>
            <TransformGroup>
              <MatrixTransform>1.27999,-1.2809,0.380134,0.400852,0.419179,0.455777</MatrixTransform>
              <MatrixTransform>-0.662414,0.0903729,-0.0931464,-0.682744,89.5811,136.703</MatrixTransform>
            </TransformGroup>
          </LinearGradientBrush.Transform>
          <GradientStop Color="#FDFBDDB2" Offset="0" />
          <GradientStop Color="#F3EFA81A" Offset="1" />
        </LinearGradientBrush>
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="4" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Round">
          <Pen.Brush>
            <SolidColorBrush Color="#FF580400" Opacity="0.992157" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="-0.662414,0.0903729,-0.0931464,-0.682744,89.5811,136.703" Figures="M87.4702,60.2132C75.7248,67.9438 64.0731,71.4223 45.9812,76.0161 29.4079,79.1305 18.7167,83.7628 5.03343,87.999 1.73517,85.4897 -1.56309,82.9804 -4.86134,80.4711 10.7544,64.3472 20.1481,43.7033 29.7795,26.7873 46.7216,7.79921 41.779,11.2674 54.7324,2.72776 73.8266,-9.90822 93.8819,0.100949 104.719,9.48852 110.996,16.4876 115.716,18.2612 115.11,26.1054 116.106,33.0665 109.061,46.8202 87.4702,60.2132z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <GeometryDrawing x:Name="path119">
      <GeometryDrawing.Brush>
        <LinearGradientBrush StartPoint="0.0853642,-0.512065" EndPoint="-0.0971978,0.704975" MappingMode="RelativeToBoundingBox" SpreadMethod="Pad" Opacity="1">
          <LinearGradientBrush.Transform>
            <TransformGroup>
              <MatrixTransform>1.27999,-1.2809,0.380134,0.400852,0.41919,0.455775</MatrixTransform>
              <MatrixTransform>0.762131,-0.0215866,0.0222492,0.78552,68.8379,14.6591</MatrixTransform>
            </TransformGroup>
          </LinearGradientBrush.Transform>
          <GradientStop Color="#FFFFFFFF" Offset="0" />
          <GradientStop Color="#FF797979" Offset="1" />
        </LinearGradientBrush>
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="4" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Round">
          <Pen.Brush>
            <SolidColorBrush Color="#FF0A0A05" Opacity="0.992157" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="0.762131,-0.0215866,0.0222492,0.78552,68.8379,14.6591" Figures="M44.43,62.2898C37.1854,68.5353 27.1814,78.5602 19.9369,84.8057 17.0367,82.316 14.1366,79.8262 11.2364,77.3365 12.4845,72.0907 11.0295,68.6983 13.0142,60.9025 24.0729,49.2556 36.4523,42.3082 54.9566,29.877 65.8336,22.998 76.6489,17.8762 95.8823,7.93509 100.402,7.43659 103.614,12.9972 102.916,13.5742 88.7246,24.5072 58.2551,50.8894 44.43,62.2898z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <GeometryDrawing x:Name="path469">
      <GeometryDrawing.Brush>
        <SolidColorBrush Color="#FFFFFFFF" Opacity="0.99" Transform="-0.434021,0.0592134,-0.0610306,-0.447343,72.8853,131.634" />
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="4" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Round">
          <Pen.Brush>
            <SolidColorBrush Color="#FF580400" Opacity="0.992157" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="-0.434021,0.0592134,-0.0610306,-0.447343,72.8853,131.634" Figures="M82.5939,56.9609C67.4481,67.1985 59.5241,69.792 46.1225,75.2955 37.1415,77.5159 29.4235,80.0424 19.1807,76.7322 16.4741,75.1627 9.66806,69.6656 9.71206,65.0753 13.7272,47.5642 19.7926,42.3188 29.7128,30.3973 37.6545,18.6613 49.465,11.0789 61.398,4.66086 78.4697,-1.86214 93.778,5.68988 101.929,12.5041 104.568,18.2824 108.934,22.5772 108.129,29.2667 104.272,40.7991 99.9919,46.0087 82.5939,56.9609z" />
      </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