[REPOST] - Drawlines with a non-solid brush vs. Drawlines with a solid brush.

[REPOST] - Drawlines with a non-solid brush vs. Drawlines with a solid brush.

Post by Broc » Sat, 01 Nov 2003 07:46:43


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?
 
 
 

[REPOST] - Drawlines with a non-solid brush vs. Drawlines with a solid brush.

Post by Bob Powell » Sat, 01 Nov 2003 19:17:30

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.yqcomputer.com/

Answer those GDI+ questions with the GDI+ FAQ
http://www.yqcomputer.com/

Read my Blog at http://www.yqcomputer.com/



Graphics.DrawLines()
is
property

 
 
 

[REPOST] - Drawlines with a non-solid brush vs. Drawlines with a solid brush.

Post by Broc » Wed, 05 Nov 2003 01:14:51

Thanks for the response. It is better, but you still can see some white
specs under the yellow line. Any other ideas?

Brock





call
LinearGradientBrush(e.ClipRectangle,
 
 
 

[REPOST] - Drawlines with a non-solid brush vs. Drawlines with a solid brush.

Post by Glenn Spie » Wed, 05 Nov 2003 21:10:10

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.Control
 
 
 

[REPOST] - Drawlines with a non-solid brush vs. Drawlines with a solid brush.

Post by Broc » Sat, 08 Nov 2003 03:53:13

his 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

"Glenn Spies" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
270,
90,
points
VS.NET
I


 
 
 

[REPOST] - Drawlines with a non-solid brush vs. Drawlines with a solid brush.

Post by JHornic » Wed, 12 Nov 2003 08:11:09

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.yqcomputer.com/



Graphics.DrawLines()
is
property