Picture in Canvas Paint event

I’m trying to optimize a Canvas Paint event with a lot of drawing and I need to have a copy of the picture in the canvas for other processes.

I have tried:

  • Do the paint in a different method and only draw the result picture in the Paint event: I get the copy but Paint is very slow
  • Do the paint in a different method and set result to Canvas.Background: slow
  • Create a parallel picture in the paint event and repeat all drawings into this picture to get the copy: best speed but must be improved
  • Using Drawinto, I can’t use it in the Paint event because it calls again Paint in a recursive loop.

Any other way to get a fast copy of the picture from a Graphics in a Paint event?

only draw what’s visible to the user, so clip to the visible region of the window

also, use the “profile code” menu item to see where you loose most of the processing time.
was a great help for me in many occasions.

Yes, but how will I get a Picture from Graphics ?

Launch a single timer in Paint, and place the Drawinto within the action event of the timer.

Michel, thanks.

This works fine and fast but there is an additional issue: the picture that I need is at middle of the Paint event, with the timer I get the final one (which has some elements I don’t want in the copy).

May be I can use Addhandler directly instead of in a timer?

You won’t be able to exactly time the moment when the paint is half way.

The other method I would try then would be to create a picture the same size as g.width and g.height, and draw into both g, and pic.graphics.

Michel,
your timer suggestion guided me in the correct way: I placed the timer in the Paint event and use his action to draw the copy in a new Picture.

Regarding that the timer is fired only at his period I’m reducing the “total” Paint time to half .