Groups | Blog | Home
all groups > dotnet drawing api > october 2003 >

dotnet drawing api : [REPOST] - Drawlines with a non-solid brush vs. Drawlines with a solid brush.


Brock
10/30/2003 4:46:43 PM
I am seeing inconsistent drawing behavior when calling Graphics.DrawLines()
with a pen created from a non solid brush vs. a Graphics.Drawlines() call
with a pen created from a solid brush. The line between the same points is
drawn differently. To see this, create a windows forms project in VS.NET
2003 and override OnPaint and add the following code:

PointF[] points = new PointF[11];
points[0] = new PointF(28, 12);
points[1] = new PointF(45, 116);
points[2] = new PointF(62, 168);
points[3] = new PointF(79, 169);
points[4] = new PointF(96, 127);
points[5] = new PointF(114, 78);
points[6] = new PointF(130, 164);
points[7] = new PointF(147, 106);
points[8] = new PointF(164, 70);
points[9] = new PointF(181, 36);
points[10] = new PointF(199, 16);

e.Graphics.FillRectangle(Brushes.Black, e.ClipRectangle);
using(LinearGradientBrush brush = new LinearGradientBrush(e.ClipRectangle,
Color.White, Color.White, LinearGradientMode.Horizontal))
using(Pen linearPen = new Pen(brush))
{
e.Graphics.DrawLines(linearPen, points);
e.Graphics.DrawLines(Pens.Yellow, points);
}

Notice that you can see the white line as well as the yellow line. Am I
doing something wrong? I need both to draw the same. Is there some property
on the Graphics object I can set?

Bob Powell [MVP]
10/31/2003 11:17:30 AM
The problem goes away when you set the PixelOffsetMode to High Quality.

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

[quoted text, click to view]

Brock
11/3/2003 10:14:51 AM
Thanks for the response. It is better, but you still can see some white
specs under the yellow line. Any other ideas?

Brock

[quoted text, click to view]

Glenn Spies
11/4/2003 1:10:10 PM
I too have the same problem that a filled path does not fill the same path
as when it is with drawpath.

Code follows:

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Drawing.Drawing2D;

namespace ControlsTest

{

/// <summary>

/// Summary description for NewControlsTest.

/// </summary>

public class NewControlsTest : System.Windows.Forms.Form

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

private System.Windows.Forms.Panel panel1;

public NewControlsTest()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

panel1.Paint += new PaintEventHandler(panel1_paint);

}

public static GraphicsPath SmoothOutline(Rectangle r, int cornerSize)

{

GraphicsPath gp = new GraphicsPath();

if (!r.IsEmpty)

{

gp.AddArc(r.Left, r.Top, cornerSize, cornerSize, 180, 90);

gp.AddArc(r.Left + r.Width - cornerSize, r.Top, cornerSize, cornerSize, 270,
90);

gp.AddArc(r.Left + r.Width - cornerSize, r.Top + r.Height- cornerSize,
cornerSize, cornerSize, 0, 90);

gp.AddArc(r.Left, r.Top + r.Height- cornerSize, cornerSize, cornerSize, 90,
90);

gp.CloseFigure();

}

return gp;

}

private void panel1_paint(object sender, PaintEventArgs e)

{

Graphics g = e.Graphics;

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

Rectangle r = new Rectangle(new Point(0,0) , panel1.Size);

int w = r.Width;

int h = r.Height;

w-=1;

h-=1;

r.Location = new Point(0,0);

r.Width = w;

r.Height = h;

System.Drawing.Drawing2D.GraphicsPath gp = SmoothOutline(r, 50);

gp.FillMode = System.Drawing.Drawing2D.FillMode.Alternate;

g.DrawPath(Pens.White, gp);

g.FillPath(Brushes.Red, SmoothOutline(r, 50)); //does not cover all of the
path


g.Clip = new Region(SmoothOutline(r, 50));


}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(NewControlsTest));

this.panel1 = new System.Windows.Forms.Panel();

this.SuspendLayout();

//

// panel1

//

this.panel1.Anchor = System.Windows.Forms.AnchorStyles.None;

this.panel1.BackColor = System.Drawing.Color.Transparent;

this.panel1.Location = new System.Drawing.Point(168, 64);

this.panel1.Name = "panel1";

this.panel1.Size = new System.Drawing.Size(300, 100);

this.panel1.TabIndex = 0;

//

// NewControlsTest

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.BackgroundImage =
((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));

this.ClientSize = new System.Drawing.Size(736, 266);

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.panel1});

this.Name = "NewControlsTest";

this.Text = "NewControlsTest";

this.ResumeLayout(false);

}

#endregion

}

}

Any suggestions would be appreciated



/Glenn

[quoted text, click to view]

Brock
11/6/2003 12:53:13 PM
This is not quite the same problem. My code was calling DrawLines with the
same points just with different Pens. Your code (DrawPath, FillPath)
exhibits the same behavior as DrawRectangle, FillRectangle. The Rectangle
drawing is documented as correct behavior so I would imagine the same thing
holds for GraphicsPaths.

Brock

[quoted text, click to view]

JHornick NO[at]SPAM online.microsoft.com
11/10/2003 11:11:09 PM
Hi,

This looks like a known issue. You might be able to work around
it by creating a new linrearPen which is simply yellow - rather
than using Pens.Yellow.

Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.



[quoted text, click to view]
AddThis Social Bookmark Button