views:

199

answers:

3

hi friends,

I have a project that in those i draw some shape from some layer. For example I have two circle in circle Layer and three rectangle in rectangle Layer and so on.I draw the result with call Layer.Draw and marge the layers result with a Graphics object. I can select one shape in picture box and specify it on layer. and i can drag it with redraw its layer and re marge all with graphics.it works ! but too slow!!

how i can optimize this?

A: 

Once upon a time I had a project where speed while drawing images was neccessary. I used the unlock method to access the bits directly (http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.unlockbits.aspx). But this method is pretty unsafe and also complicated, so you should avoid this, whenever you can.

Just try to optimize your program and remove unneccesary draws. Primary draws to the GUI are very slow, so try to not update the picture box permanently but only when it is neccesarry.

Emiswelt
I saw in some books that for show image to user, experts use custom control. and draw image into those, and when need to re draw image use control.Invalidate() to do this. what's your idea? if i use this method i can solve the problem? I'm testing it's now!
ali moharrami
this was not the way I ment, but you can try it. Try to set the DoubleBuffered property to true for your control, this will boost the performance.
Emiswelt
A: 

I think this article has exactly the code you are looking for: Flicker free drawing using GDI+ and C#.

David Gannon
A: 

hi friends,

in old solution i draw shapes into layer.image and in on Paint event marge they with e.Graphic. I solve this problem with passing the graphic object into layers and draw shapes with it. my program work very good!

ali moharrami