Click to See Complete Forum and Search --> : GDI+ (Graphics class) and multi-core


DrBob
October 30th, 2009, 11:02 AM
Hi everyone,

I posted this in the "Graphics Programming" forum...

I wrote a C# application (VS2005) that takes a bunch of images and resize them. Now that I have a quad core, I rewrote it to use threads. Each thread load an image and resize it. After many attempts, I can't get the CPU to work over 25%-29% and that means that only 1 core is used. It seems the bottleneck is the DrawImage() method. It looks like this method only handle 1 thread at a time. Is it possible that DrawImage() uses a lock?

Thx in advance for any hints!

sotoasty
October 30th, 2009, 11:42 AM
I would think the DrawImage would actually use the Graphics Processor. Not the CPU.

DrBob
October 30th, 2009, 12:23 PM
Interesting point because if it's true then it could explain why DrawImage() runs 1 job at a time. I read this blog (link below) and it looks like GDI+ is based on a software engine.

http://blogs.technet.com/thomasolsen/archive/2008/10/29/introducing-the-microsoft-direct2d-api.aspx

Ok, I finally found this info. GDI+ is using a global lock so threading GDI operations is useless (even if each thread has its own Graphics instance):
http://social.msdn.microsoft.com/forums/en-US/winforms/thread/25cceaa4-f058-482a-8381-03698f73651a/

BigEd781
October 30th, 2009, 01:22 PM
If you need high performance graphics I would suggest using DirectX. If that is overkill and you only need to resize some images, why not do it yourself? Resizing an image is not very difficult (especially if you are only down-sampling) and you can find many algorithms available on the web.