Reputation: 129
Hi I Wonder why usual graphic speed is so much slower than VB6 in C# code , here is a sample code which does the same thing in VB6 and C# , it takes 1.7 Secs in VB6 on my computer and 4.2 Secs in C# Could someone please tell me why and also if there is a better and faster way in c# .
Thanks
C# Code
Bitmap MyBitmap = new Bitmap(1024, 768);
Graphics g = Graphics.FromImage(MyBitmap);
DateTime STime = DateTime.Now;
Pen MyPen = new Pen(Color.Black);
for (int i = 0; i < 100000; i++)
{
g.DrawLine (MyPen, 0, 0, 1024, 768);
}
MessageBox.Show(DateTime.Now.Subtract(STime).TotalMilliseconds.ToString());
VB6 Code :
Me.AutoRedraw = True
t = Timer
For i = 1 To 100000
Me.Line (0, 0)-(1024, 768), 0
Next
MsgBox (Timer - t)
Upvotes: 3
Views: 452
Reputation: 8696
VB6 goes straight to GDI. C#, which uses System.Drawing, uses GDI+. GDI+ is antialiased and uses 32bpp. Basically, there is a bunch of overhead.
Upvotes: 4