HighTechTalks DotNet Forums  

Render using DashPattern is very very slow

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Render using DashPattern is very very slow in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Patrick van Dijk
 
Posts: n/a

Default Render using DashPattern is very very slow - 12-01-2006 , 09:41 AM







Take a look at the following sample code....the part which renders
using a DashPattern is very very slow.
The same rendering using a Solid pen is hundreds of times faster.
Anyone, any idea why?

using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

public class MyClass : Form
{
static internal void InitialiseGraphics(Graphics graphics)
{
// We must set these value, specifically the PixelOffsetMode,
otherwise we are getting white spaces between tiles of raster
Console.WriteLine("PageUnit: {0}", graphics.PageUnit);

graphics.PixelOffsetMode = PixelOffsetMode.None;
graphics.PageUnit = GraphicsUnit.Pixel;

graphics.Clip = new Region(new Rectangle(0, 0, 400, 400));

//graphics.SmoothingMode = SmoothingMode.None;
//graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
//graphics.CompositingMode = CompositingMode.SourceOver;
//graphics.CompositingQuality = CompositingQuality.HighSpeed;
//graphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.ClearTypeGri dFit;
}

public static void Main()
{
MyClass my = new MyClass();

my.Location = new Point(10, 10);
my.Size = new Size(500, 500);

my.Show();

Pen pen = new Pen(Color.Blue, 2);
pen.DashPattern = new float[] { 2.5F, 5.0F };
pen.DashStyle = DashStyle.Custom;

Pen pen2 = new Pen(Color.Yellow, 3);

Brush brush = new SolidBrush(Color.FromArgb(100, 0, 200, 100));

Graphics graphics = my.CreateGraphics();
InitialiseGraphics(graphics);

PointF[] points = new PointF[2];
points[0] = new PointF(-2000000, -2001000);
points[1] = new PointF(2000100, 2000000);

DateTime beg = DateTime.Now;
graphics.DrawLines(pen2, points);
DateTime end = DateTime.Now;
Console.WriteLine("Time for Pen(3): {0}", end - beg);

beg = DateTime.Now;
graphics.DrawLines(pen, points);
end = DateTime.Now;
Console.WriteLine("Time for Dashed: {0}", end - beg);


System.Threading.Thread.Sleep(2000);

}

}



The result:

Time for Pen(3): 00:00:00.0156250
Time for Dashed: 00:00:06.4375000


Reply With Quote
  #2  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Render using DashPattern is very very slow - 12-01-2006 , 12:08 PM






Because a dash pattern is hard to draw?

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

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



"Patrick van Dijk" <patrick.van.dijk (AT) gmail (DOT) com> wrote

Quote:
Take a look at the following sample code....the part which renders
using a DashPattern is very very slow.
The same rendering using a Solid pen is hundreds of times faster.
Anyone, any idea why?

using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

public class MyClass : Form
{
static internal void InitialiseGraphics(Graphics graphics)
{
// We must set these value, specifically the PixelOffsetMode,
otherwise we are getting white spaces between tiles of raster
Console.WriteLine("PageUnit: {0}", graphics.PageUnit);

graphics.PixelOffsetMode = PixelOffsetMode.None;
graphics.PageUnit = GraphicsUnit.Pixel;

graphics.Clip = new Region(new Rectangle(0, 0, 400, 400));

//graphics.SmoothingMode = SmoothingMode.None;
//graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
//graphics.CompositingMode = CompositingMode.SourceOver;
//graphics.CompositingQuality = CompositingQuality.HighSpeed;
//graphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.ClearTypeGri dFit;
}

public static void Main()
{
MyClass my = new MyClass();

my.Location = new Point(10, 10);
my.Size = new Size(500, 500);

my.Show();

Pen pen = new Pen(Color.Blue, 2);
pen.DashPattern = new float[] { 2.5F, 5.0F };
pen.DashStyle = DashStyle.Custom;

Pen pen2 = new Pen(Color.Yellow, 3);

Brush brush = new SolidBrush(Color.FromArgb(100, 0, 200, 100));

Graphics graphics = my.CreateGraphics();
InitialiseGraphics(graphics);

PointF[] points = new PointF[2];
points[0] = new PointF(-2000000, -2001000);
points[1] = new PointF(2000100, 2000000);

DateTime beg = DateTime.Now;
graphics.DrawLines(pen2, points);
DateTime end = DateTime.Now;
Console.WriteLine("Time for Pen(3): {0}", end - beg);

beg = DateTime.Now;
graphics.DrawLines(pen, points);
end = DateTime.Now;
Console.WriteLine("Time for Dashed: {0}", end - beg);


System.Threading.Thread.Sleep(2000);

}

}



The result:

Time for Pen(3): 00:00:00.0156250
Time for Dashed: 00:00:06.4375000




Reply With Quote
  #3  
Old   
PT
 
Posts: n/a

Default Re: Render using DashPattern is very very slow - 12-04-2006 , 04:50 AM



Take a sheet of A4, take a ruler and pen, first draw a straight line, pretty
quick, now draw some dash dot same thing applies, with dash dot there's
extra steps the draw functions needs to take as you can pass in a variable
lengthed dash dot pattern etc, so it's doing more work, so takes longer.

Just verbose on Bob's reply

"Bob Powell [MVP]" <bob (AT) _spamkiller_ (DOT) bobpowell.net> wrote

Quote:
Because a dash pattern is hard to draw?

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

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



"Patrick van Dijk" <patrick.van.dijk (AT) gmail (DOT) com> wrote in message
news:1164984081.478978.131510 (AT) 16g2000cwy (DOT) googlegroups.com...

Take a look at the following sample code....the part which renders
using a DashPattern is very very slow.
The same rendering using a Solid pen is hundreds of times faster.
Anyone, any idea why?

using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

public class MyClass : Form
{
static internal void InitialiseGraphics(Graphics graphics)
{
// We must set these value, specifically the PixelOffsetMode,
otherwise we are getting white spaces between tiles of raster
Console.WriteLine("PageUnit: {0}", graphics.PageUnit);

graphics.PixelOffsetMode = PixelOffsetMode.None;
graphics.PageUnit = GraphicsUnit.Pixel;

graphics.Clip = new Region(new Rectangle(0, 0, 400, 400));

//graphics.SmoothingMode = SmoothingMode.None;
//graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
//graphics.CompositingMode = CompositingMode.SourceOver;
//graphics.CompositingQuality = CompositingQuality.HighSpeed;
//graphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.ClearTypeGri dFit;
}

public static void Main()
{
MyClass my = new MyClass();

my.Location = new Point(10, 10);
my.Size = new Size(500, 500);

my.Show();

Pen pen = new Pen(Color.Blue, 2);
pen.DashPattern = new float[] { 2.5F, 5.0F };
pen.DashStyle = DashStyle.Custom;

Pen pen2 = new Pen(Color.Yellow, 3);

Brush brush = new SolidBrush(Color.FromArgb(100, 0, 200, 100));

Graphics graphics = my.CreateGraphics();
InitialiseGraphics(graphics);

PointF[] points = new PointF[2];
points[0] = new PointF(-2000000, -2001000);
points[1] = new PointF(2000100, 2000000);

DateTime beg = DateTime.Now;
graphics.DrawLines(pen2, points);
DateTime end = DateTime.Now;
Console.WriteLine("Time for Pen(3): {0}", end - beg);

beg = DateTime.Now;
graphics.DrawLines(pen, points);
end = DateTime.Now;
Console.WriteLine("Time for Dashed: {0}", end - beg);


System.Threading.Thread.Sleep(2000);

}

}



The result:

Time for Pen(3): 00:00:00.0156250
Time for Dashed: 00:00:06.4375000






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.