c# and GDI graphics

D

Daniel

Hi

I had an app i write on DirectX that will nearly always run in a windowed
situation. It could also have many instances running at a time and as such
to keep the cpu usage down i had a frame refresh sticker ever 32 ms rather
than maximum speed. This worked great but then i thought as all my graphics
are 2D this is huge over kill.

So i decided to port it to GDI graphics. At first a good idea i could easily
do everything i was using with Directx but less end requirements for the
user and much smaller code and less 'set up' code.

However first i found severe flicker with the GDI solution. So i implemented
a double buffer which solved the flicker but all my transparent imagery was
lost (due to the doubling up). I found if i clear the back buffer to prevent
doubling up i get a flicker again.

this all aside a even bigger problem, my cpu usage is FAR worse than it was
with directx. With a refresh every second it still spikes to 18% for one
instance. I have seen rival products on the market use simple graphics who
keep the cpu under 5% when i had 10 instances open.

What am i doing wrong? Is it possible to make an efficient GDI app?
 
N

Nicholas Paldino [.NET/C# MVP]

Daniel,

It is possible, but the one main advantage that the DirectX solution has
over the GDI app is that DirectX is going to utilize hardware acceleration
when it can, whereas GDI won't (you are simply pushing pixels to the screen
there, very low level).

If your requirements and your development permit (XP/2003 and above,
don't mind using the .NET 3.0 framework which is not even in beta yet), you
might want to try using the Windows Presentation Foundation. It will give
you the benefits of hardware acceleration (it utilizes DX underneath the
covers) and an easy programming model.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top