Monday, May 24, 2010

I have a very basic question about drawing in C#. A best answer will be awarded.?

I have a class that draws itself. When the class is instantiated there are a lot of calculations. things like:





Rectangle leftCellRectangle = new Rectangle(x1 + arcWidth, y1, (arcWidth % 2 == 0) ? arcWidth : arcWidth+20, cellHeight);


Rectangle rightCellCircle = new Rectangle(x1 + (cellWidth * (order - 1)), y1, cellWidth, cellHeight);





...maybe 30 lines of calculations like that. All of these calculations draw only ONE of the instances of this class that will be on the screen and there could be any number of instances on the screen at a time.





So, I dont want the computer to have to do all of those calculations every single time it has to repaint the window (due to minimizing, window dragged over top, etc). Is there a standardized way of doing this?





I have read a ton of tutorials on the GDI but I can't find the answers I am looking for.





If you can answer my question I will give you full points and be very appreciative.





Thanks

I have a very basic question about drawing in C#. A best answer will be awarded.?
look into double buffering. This is where you paint to an offscreen bitmap when youre drawing the image





Then when windows is repainting the image, it just paints the bitmap to screen instead of drawing all the shapes again





You update the bitmap instead of the screen





Theres probably an easy way to do this in c#, search for z-buffer or double buffering





Maybe its even a boolean property of the Canvas object, if youre lucky
Reply:try clearing memory


No comments:

Post a Comment