简体   繁体   English

如何使用GDI +绘制填充颜色的(bezier)路径?

[英]How to draw a (bezier) path with a fill color using GDI+?

I am making a SVG renderer for Windows using the Windows API and GDI+. 我正在使用Windows API和GDI +为Windows制作SVG渲染器。 SVG allows setting the 'fill' and 'stroke' style attributes on a Path. SVG允许在Path上设置'fill'和'stroke'样式属性。 I am having some difficulty with the implementation of the 'fill' attribute. 我在执行'fill'属性时遇到了一些困难。

The following path represents a spiral: 以下路径代表螺旋:

    <svg:path style="fill:yellow;stroke:blue;stroke-width:2"
              d="M153 334
                C153 334 151 334 151 334
                C151 339 153 344 156 344
                C164 344 171 339 171 334
                C171 322 164 314 156 314
                C142 314 131 322 131 334
                C131 350 142 364 156 364
                C175 364 191 350 191 334
                C191 311 175 294 156 294
                C131 294 111 311 111 334
                C111 361 131 384 156 384
                C186 384 211 361 211 334
                C211 300 186 274 156 274" />

The fill color is yellow, and it should fill the entire shape, this is however what I get: 填充颜​​色是黄色,它应该填满整个形状,但这是我得到的:

在此输入图像描述

My GDI+ calls look like this: 我的GDI +调用看起来像这样:

Gdiplus::GraphicsPath bezierPath;
bezierPath.AddBeziers(&gdiplusPoints[0], gdiplusPoints.size());
g.FillPath(&solidBrush, &bezierPath);
g.DrawPath(&pen, &bezierPath);

Apparently the code is correct for drawing the shape, but not for filling it. 显然,代码对于绘制形状是正确的,但不适合填充它。 Can anyone help me in figuring out what's going wrong? 任何人都可以帮我弄清楚出了什么问题吗?

尝试将GraphicsPath的FillMode属性设置为FillMode :: Winding,这是一种适合您需要的替代填充方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM