Click here to Skip to main content
15,891,204 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 Canvas.Left="4.36491586355419" Canvas.Top="-18.1113567643004">
    <Canvas>
      <Path Data="F1M41.188971,42.343147A14.407301,4.0658641,0,1,1,12.374369,42.343147A14.407301,4.0658641,0,1,1,41.188971,42.343147z" Stroke="{x:Null}" StrokeThickness="1" Opacity="0.3">
        <Path.Fill>
          <RadialGradientBrush Center="26.78167,42.343147" RadiusX="14.407301" RadiusY="14.407301" GradientOrigin="26.78167,42.343147" MappingMode="Absolute">
            <RadialGradientBrush.GradientStops>
              <GradientStop Color="#FF000000" Offset="0" />
              <GradientStop Color="#00000000" Offset="1" />
            </RadialGradientBrush.GradientStops>
            <RadialGradientBrush.Transform>
              <MatrixTransform Matrix="1,0,0,0.282209008932114,1.67921200710819E-15,30.3935508728027" />
            </RadialGradientBrush.Transform>
          </RadialGradientBrush>
        </Path.Fill>
        <Path.RenderTransform>
          <MatrixTransform Matrix="1.33836996555328,0,0,1,-20.926399230957,-3.409010887146" />
        </Path.RenderTransform>
      </Path>
      <Canvas>
        <Canvas>
          <Canvas>
            <Path Data="M81.189325,8.8512115L75.593983,14.505723 60.324794,46.150492C59.091904,49.407024,63.727034,51.320174,65.336892,48.436664L80.231414,16.856367 81.189325,8.8512115z" Fill="#FFCB9022" Stroke="#FF5C410C" StrokeThickness="1.00000083446503" StrokeMiterLimit="4" />
            <Path Data="M63.226659,41.398C63.226659,41.398 63.327968,42.834989 64.580911,43.390907 65.871703,43.963619 67.237126,43.376936 67.237126,43.376936L64.794871,48.421105C64.794871,48.421105 63.921152,49.877754 61.954609,49.092304 60.014929,48.317582 60.784239,46.41092 60.784239,46.41092L63.226659,41.398z" Stroke="{x:Null}" StrokeThickness="1">
              <Path.Fill>
                <LinearGradientBrush StartPoint="60.6286827749897,46.3179821529337" EndPoint="65.5139773120177,48.3744028083719" MappingMode="Absolute" SpreadMethod="Pad">
                  <LinearGradientBrush.GradientStops>
                    <GradientStop Color="#FFFFD1D1" Offset="0" />
                    <GradientStop Color="#FFFF1D1D" Offset="0.5" />
                    <GradientStop Color="#FF6F0000" Offset="1" />
                  </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
              </Path.Fill>
            </Path>
            <Path Data="M63.226659,41.398C63.226659,41.398 63.327968,42.834989 64.580911,43.390907 65.871703,43.963619 67.237126,43.376936 67.237126,43.376936L66.247658,45.38217C66.247658,45.38217 64.933158,46.216127 63.561344,45.615052 62.151825,44.997456 62.237191,43.403234 62.237191,43.403234L63.226659,41.398z" Stroke="{x:Null}" StrokeThickness="1">
              <Path.Fill>
                <LinearGradientBrush StartPoint="63.0497043775395,43.3989559389011" EndPoint="65.8710433587257,45.0716414680355" MappingMode="Absolute" SpreadMethod="Pad">
                  <LinearGradientBrush.GradientStops>
                    <GradientStop Color="#FFC1C1C1" Offset="0" />
                    <GradientStop Color="#FFACACAC" Offset="1" />
                  </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
              </Path.Fill>
            </Path>
            <Path Data="M80.47809,10.282021L76.001816,14.805631C76.822195,16.301338,78.170037,17.07551,79.730379,16.661047L80.47809,10.282021z" Stroke="{x:Null}" StrokeThickness="1">
              <Path.Fill>
                <RadialGradientBrush Center="29.053354,27.640751" RadiusX="3.2408545" RadiusY="3.2408545" GradientOrigin="29.053354,27.640751" MappingMode="Absolute">
                  <RadialGradientBrush.GradientStops>
                    <GradientStop Color="#FFE7E2B8" Offset="0" />
                    <GradientStop Color="#00E7E2B8" Offset="1" />
                  </RadialGradientBrush.GradientStops>
                  <RadialGradientBrush.Transform>
                    <MatrixTransform Matrix="0.0153767000883818,2.92352700233459,2.02969098091125,-0.0106754396110773,20.3909797668457,-69.7266464233398" />
                  </RadialGradientBrush.Transform>
                </RadialGradientBrush>
              </Path.Fill>
            </Path>
            <Path Data="M79.078925,11.63315L80.664108,9.9997888 80.363939,12.345152C79.646349,12.567679,79.300467,12.163243,79.078925,11.63315z" Stroke="{x:Null}" StrokeThickness="1">
              <Path.Fill>
                <LinearGradientBrush StartPoint="79.8746427890874,11.4102127092119" EndPoint="79.5298234564087,11.2078623396181" MappingMode="Absolute" SpreadMethod="Pad">
                  <LinearGradientBrush.GradientStops>
                    <GradientStop Color="#FF000000" Offset="0" />
                    <GradientStop Color="#FFC9C9C9" Offset="1" />
                  </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
              </Path.Fill>
            </Path>
            <Path Data="M75.970567,14.805795L77.228768,16.3617 64.439998,43.316362C63.581628,42.876439,63.348884,42.080316,63.26774,41.419121L75.970567,14.805795z" Fill="#5DFFFFFF" Stroke="{x:Null}" StrokeThickness="1" />
            <Path Data="M79.792879,16.660719L79.043875,16.852161 66.494476,43.620552C66.494476,43.620552,67.107516,43.507166,67.242681,43.400734L79.792879,16.660719z" Fill="#5D000000" Stroke="{x:Null}" StrokeThickness="1" />
            <Canvas.RenderTransform>
              <MatrixTransform Matrix="1,0,0,1,32.5603103637695,-8.17560577392578" />
            </Canvas.RenderTransform>
          </Canvas>
          <Path Data="M113.29217,1.848589L108.5192,6.7099482 100.2107,23.98987 108.91695,7.1960841 113.29217,1.848589z" Fill="#B9FFFFFF" Stroke="{x:Null}" StrokeThickness="1" Opacity="0.72527472" />
          <Path Data="M113.15959,1.848589L112.27571,8.5661035 105.514,22.973404 112.05474,8.5219093 111.52441,8.6102976 113.15959,1.848589z" Fill="#6AFFFFFF" Stroke="{x:Null}" StrokeThickness="1" Opacity="0.41758243" />
          <Canvas.RenderTransform>
            <MatrixTransform Matrix="-0.958887219429016,-0.283787310123444,0.283787310123444,-0.958887219429016,199.699691772461,82.0039825439453" />
          </Canvas.RenderTransform>
        </Canvas>
        <Canvas.RenderTransform>
          <MatrixTransform Matrix="-0.0551202110946178,-0.998479723930359,-0.998479723930359,0.0551202110946178,58.2863960266113,126.233383178711" />
        </Canvas.RenderTransform>
      </Canvas>
    </Canvas>
  </Canvas>
</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