-1

I'm working on a college project (simulation) that needs to draw a lot of lines and objects to a custom UserControl. My current approach is just to redraw everything for every tick / update loop using Invalidate(). But it sure needs a lot of time to draw (which is resulting in very low FPS) especially when I need to draw thousands of lines and rectangles.

So how can I only re-draw a specific (group of) objects that move in every update loop and only re-draw the rest (the rarely updated objects) when needed? Or is there other way to optimize the way I draw in this problem?

Myung
  • 1
  • 1
  • Please google opengl and DirectX. :) – neohope Sep 01 '16 at 10:30
  • What are you targetting: Winforms, WPF, ASP..? __Always__ tag your question correctly! - For Winforms [see here!](http://stackoverflow.com/questions/27623365/existing-graphics-into-bitmap/27647011#27647011) – TaW Sep 01 '16 at 11:18
  • @TaW I'm targetting winforms. Tag edited. Thanks for the link, I'll try it – Myung Sep 02 '16 at 06:19

1 Answers1

0

My idea would be the following:

Draw your Control onto a Bitmap (or other image format) once, and save that Image. Then display that Bitmap on your Control. (Assuming you use a Control that can do that, i.e an ImageBox, not sure what would be best for that).

Whenever you update your graphic, keep track of what sections of your Control may be outdated, then redraw only these sections (drawing only the objects that touch that section), and copy the other sections from your saved image.

Display (and save) the new Image.