Faster than GDI+

  • Thread starter Thread starter Scatropolis
  • Start date Start date
S

Scatropolis

Is GDI as fast as drawing gets? I'm writing a program that deals with
drawing a ridiculous amount of lines and am finding GDI a little slow, or just
maybe how I'm using it. I was looking at some DirectX documents and wondering
if that was the way to go. Any help would be appreciated.

Thanks.
 
I'm fairly confident that DirectX would be faster, try porting it to DirectX
and let me know how it goes.
 
Is GDI as fast as drawing gets?

If you're drawing directly to the screen, then yes, that's it. Keep
in mind that .NET languages have a P/Invoke overhead for calling GDI
routines, too!

However, you could lock a GDI+ bitmap in memory and directly
manipulate the bits, then copy the result back to your control surface
-- you'll have to write your own drawing routines but they should be
plenty fast. And you won't have to mess with DirectX.
 
How exactly would I go about doing that. At the moment I'm using a Image in
memory then showing it in a pictureBox. What do you mean?
thanks
 
Take a look at the Bitmap.LockBits method.

How exactly would I go about doing that. At the moment I'm using a Image in
memory then showing it in a pictureBox. What do you mean?
thanks
 
Did you set the style of the control you are painting on to DoubleBuffer?
This will make sure all the drawing is done in memory first then the final
result will be painted to the surface instead of drawing each line or object
realtime.

See this page here:

http://msdn.microsoft.com/library/d...stemwindowsformscontrolclasssetstyletopic.asp

For controls that I do my own painting for, DoubleBuffer, UserPaint,
AllPaintingInWmPaint are always on, and so is TransparentBackColor just for
fun and special effects. Sometimes, ResizeRedraw is also handy if your
control needs to repaint when resized automatically.

I've noticed with these styles on, GDI+ is extremely fast and I don't notice
any unusual slowness at all. But let me know if that helps or not.

If you need to do a lot of realtime drawing without slowing up the rest of
your app, worker threads might also help.
 
At the moment I have the drawing all done on an Image in another class. Then
just drawn on the pictureBox. Though I'm wonder if all those white spaces
are causing my bottle neck.
 
Back
Top