开发者

WPF: is it possible to render a circle using GeometryDrawing?

开发者 https://www.devze.com 2023-01-25 00:03 出处:网络
I\'ve got a GeometryDrawing similar like this: <DrawingImage x:Key=\"{ComponentResourceKey TypeInTargetAssembly={x:Type wpfhlp:FokusGroupBox},ResourceId=IconTest}\">

I've got a GeometryDrawing similar like this:

<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type wpfhlp:FokusGroupBox},ResourceId=IconTest}">
  <DrawingImage.Drawing>
    <DrawingGroup>
      <GeometryDrawing Brush="Black" Geometry="M0,260 L0,600 L110,670 L110,500 L190,550 L190,710 L300,775 L300,430 L150,175"/>
    <开发者_Python百科/DrawingGroup>
  </DrawingImage.Drawing>
</DrawingImage>

Now I'd like to draw a circle instead, but I only can find commands to move, draw a line, nothing to draw a circle.

Is there some way to get the GeometryDrawing to draw a circle?


....
<GeometryDrawing Brush="Black">
    <GeometryDrawing.Geometry>
        <EllipseGeometry Center="0,0" RadiusX="1" RadiusY="1" />
    </GeometryDrawing.Geometry>
</GeometryDrawing>

Alternatively, you can also use Path Markup Syntax to draw two elliptic arcs (upper and lower half of the circle):

<GeometryDrawing Brush="Black" Geometry="M -1,0 A 1,1 0 1 1 1,0 M -1,0 A 1,1 0 1 0 1,0" />

In case you're wondering, this is what those cryptic drawing instructions mean:

  • M -1,0: Start drawing at point (-1, 0).
  • A 1,1 0 1 1 1,0: Draw an elliptic arc with radius (1, 1) to point (1, 0). The single-digit flags in between mean: no rotation (0), angle 180° or larger (1), positive-angle direction (1, meaning clockwise). This yields the upper half of the circle.
  • M -1,0: Start drawing again at point (-1, 0)
  • A 1,1 0 1 0 1,0: Draw the same arc as before, only this time in negative-angle direction (0, meaning counter-clockwise).


<Path Stretch="Fill" 
      Fill="Transparent" 
      Stroke="Black" 
      StrokeThickness="5" 
      Data="M 0,0 A 180,180 180 1 1 1,1 Z"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消