![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |