Click here to Skip to main content
15,884,838 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.3K   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="path59">
      <GeometryDrawing.Brush>
        <RadialGradientBrush Center="-4.91305,-1.24553" RadiusX="1.04814" RadiusY="1.04814" GradientOrigin="-4.91305,-1.24553" MappingMode="RelativeToBoundingBox" SpreadMethod="Pad" Opacity="0.7">
          <RadialGradientBrush.Transform>
            <TransformGroup>
              <MatrixTransform>0.64832,0.655339,-0.773311,0.760765,0.302596,0.128551</MatrixTransform>
              <MatrixTransform>1.38019,-0.788339,1.41315,0.785567,-496.687,186.349</MatrixTransform>
            </TransformGroup>
          </RadialGradientBrush.Transform>
          <GradientStop Color="#FF73FFFF" Offset="0" />
          <GradientStop Color="#FF2EA6B9" Offset="0.2809" />
          <GradientStop Color="#FF006B8B" Offset="1" />
        </RadialGradientBrush>
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="2.81032" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter">
          <Pen.Brush>
            <SolidColorBrush Color="#FF1C6772" Opacity="0.69176449999999989" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="1.38019,-0.788339,1.41315,0.785567,-496.687,186.349" Figures="M316.063,290.477C316.063,290.477 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 281.502,325.038 281.502,325.038 283.377,326.914 286.294,328.355 288.946,328.355 291.598,328.355 293.768,326.914 295.644,325.039L316.064,304.619C319.329,301.028 318.398,298.532 318.993,297.548 318.993,294.896 317.939,292.352 316.063,290.477z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
    <GeometryDrawing x:Name="path126">
      <GeometryDrawing.Brush>
        <RadialGradientBrush Center="2.74349,1.72271" RadiusX="1.21081" RadiusY="1.21081" GradientOrigin="2.74349,1.72271" MappingMode="RelativeToBoundingBox" SpreadMethod="Pad" Opacity="0.7">
          <RadialGradientBrush.Transform>
            <TransformGroup>
              <MatrixTransform>-0.798481,-0.795015,0.630725,-0.62439,0.548676,1.02489</MatrixTransform>
              <MatrixTransform>-1.33563,0.81756,-1.35899,-0.827095,988.771,334.924</MatrixTransform>
            </TransformGroup>
          </RadialGradientBrush.Transform>
          <GradientStop Color="#FF73FFFF" Offset="0" />
          <GradientStop Color="#FF2EA6B9" Offset="0.2809" />
          <GradientStop Color="#FF006B8B" Offset="1" />
        </RadialGradientBrush>
      </GeometryDrawing.Brush>
      <GeometryDrawing.Pen>
        <Pen Thickness="2.79922" StartLineCap="Flat" EndLineCap="Flat" LineJoin="Miter">
          <Pen.Brush>
            <SolidColorBrush Color="#FF1C6772" Opacity="0.69176449999999989" />
          </Pen.Brush>
        </Pen>
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Transform="-1.33563,0.81756,-1.35899,-0.827095,988.771,334.924" Figures="M316.063,290.477C316.063,290.477 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 281.502,325.038 281.502,325.038 283.377,326.914 286.294,328.355 288.946,328.355 291.598,328.355 293.768,326.914 295.644,325.039L316.064,304.619C319.329,301.028 318.398,298.532 318.993,297.548 318.993,294.896 317.939,292.352 316.063,290.477z" />
      </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