在GraphicsPath上绘制边框或轮廓?

时间:2017-11-29 19:18:53

标签: c# .net paint gdi+

我正在制作一个地图绘制程序,其行为与典型的“Paint”程序非常相似。我希望我的海岸线能够突出,所以在我画的路径周围添加一个边框/轮廓,如下图所示,这就是我的目标: land with outlines

当用户绘制“土地”时,边框应该是实时的。

现在,我的软件表现如下: land with no outlines

目前我的绘画与Graphics.DrawLine()一起使用,但我猜我需要将线条添加到GraphicsPath并以某种方式跟踪路径上的轮廓以获得所需的效果。

这是我的代码的重要部分。所有绘图都是在我制作的Canvas对象中完成的,这只是PictureBox的一些自定义逻辑:

private void Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseDown) // if a mouse button is being pressed
            {
                if (currentTool == Tools.LandWater) // if the current tool is the land placing tool
                {
                    SetupGraphics(); // pretty much just gr = this.CreateGraphics();

                    Brush penBrush = null;

                    if (IsTextureBrush) // if the canvas object is going to use a texture brush or solid brush
                    {
                        Image texture = this.PaperTexture;
                        if (e.Button == MouseButtons.Left) texture = this.LandTexture1;
                        else if (e.Button == MouseButtons.Right) texture = this.WaterTexture; // if user right clicks, water is placed

                        penBrush = new TextureBrush(texture);
                    }
                    else
                    {
                        penBrush = new SolidBrush(BrushColour);
                    }

                    using (Pen p = new Pen(penBrush, this.BrushSize))
                    {
                        p.StartCap = System.Drawing.Drawing2D.LineCap.Round;
                        p.EndCap = System.Drawing.Drawing2D.LineCap.Round;
                        p.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;

                        gr.DrawLine(p, lastMouseLocation, e.Location);

                    }

                    lastMouseLocation = e.Location; // originally set in MouseDown as e.Location       
                }
            }


        }

有没有人知道我哪里可以开始?我查看了一些Win32 API调用和东西,但没有一个按预期工作。

0 个答案:

没有答案