Optimizing realtime GDI+ Bitmap manipulation

Frasse

Member
Joined
Jul 20, 2003
Messages
13
Earlier I posted another thread in the Direct X forum http://www.computerhelp.forum/t74651/s.html

This question was about if it was possible to output Direct X graphics in a UserControl, and weather it is worth the effort or not. In this post I say that I dont know if the performance will be enough, I also describes the architectural solution (small explenation).

Now I know that its not possible to get decent speed out of a realtime cut, modify and paste code using bitmaps and my solution. However, I posted another thread in the VB.NET language specific forum: http://www.computerhelp.forum/t74683/s.html

This post is about optimizing the inner loops of the manipulation code. So at last I turn my questions to you GDI+ coders to ask if there is a better way then actually cutting and pasting Bitmaps.

/Frasse
 
good question. i want to know the answer too. prepare for disappointment though. GDI+ is pretty slow, may not suitable for realtime graphics drawing.
 
Atm Im manipulating an area of 300x300 size, its too slow on my PII 733Mhz.

When isolating the issues, for sure it takes time to do the GDI+ based operations:

Code:
 - Paste back the last saved Bitmap
 - Cut out the new one
   - Create a new Bitmap based on the cuted
 - Paste the modified on the cut out area

But between cuting out the new and pasting the modified this is what i need to do:

Code:
 - Iterate thru Y-Axis (300 times)
    - Iterate thru X-Axis (300 times)

       (Following code runs 300*300 times per frame)

       - Read 2 arrays (_XMap and _YMap)
       - Read source bitmap pixel (Guess you can call this an GDI+ operation)
       - Write dest bitmap pixel (This might also be a GDI+ operation)

    - End of X-Axis iteration
 - End of Y-Axis iteration

For sure it could not take too much time reading those lookup arrays which is defined as Private _XMap(,) As Integer (_YMap is naturally equaly defined).

So I guess that its those Bitmap.Getpixel and Bitmap.Setpixel that takes too much time in this innerloop.

Any suggestions? Im about to look more into dubbelbuffered GDI+ to see if there is any way I can access the Bitmap object data as an array instead of using those methods.

Btw. Please read my other inlays (linked in the first post of this thread) to understand more of what Im trying to acomplish. Also we wouldnt like to have them OS X guys laughing at us because we cant add nice features to our most extendable OS? I have one of them with his OS X LaunchBar featured Mac on the other side of my desk, he is an musician :p..

/Frasse
 
Thank you man!

A moment ago I thoght most subscribers to this forum avoided complicated issues, but now I see that there are some guys out there who knows what they are doing. ;) No offence everyone else out there :rolleyes:

This is exactly the kind of information that is usefull ;). Now I might be able to reduce ALOT of stupid GDI+ operations. Purely spontaniously Id say that I just had a good idea, which I just deleted since it still had too many GDI+ operations. I was hoping that I could get away with just creating a bitmap and draw it on the control Graphics surface each frame. But now I realise I need to put the old one back aswell. So Ill see about how to solv this the best way soon.

Ill post my upcomming solutions..

Thanks

/Frasse
 
I just took another look on your code. DAMN its fast! Its fast on big areas aswell. Nice!

Anyways, your code showed me that it was possoble to do nice fast graphics using a bitmap that fills the whole area, an bitmap that is drawn on the control Graphics surface each time it should be updated. I thoght that this would be too slow, so I update small areas instead resulting in more GDI+ operations. So I guess Ill be trying that out ;)..

/Frasse
 
Back
Top