I currently work in Windows Form Apps and am doing what is essentially a map editor for the game. The way I did this is the central TabControl , where each TabPage contains a custom PictureBox control, and all other interface elements are located around this central TabControl . PictureBox uses its Paint event to draw everything that is placed on the map, and therefore draws several images of different sizes, revolutions and weights, etc. For a single PictureBox . So far, everything went well. TabPage is essentially used as a viewport for a PictureBox and has a size (1280x720).
The problem is the scale at which the cards are produced. The average (as well as maximum) size of the map on the screen is about 19200x10800 pixels and can consist of hundreds of objects at any point. When drawing only the 19200x10800px background, the PictureBox starts to flicker when it is redrawn and renders the program unusable. Since the map is so large that you can swing around them, and this is where it really flickers. In addition, I do not want to use a 19200x10800px image source, if possible, for the sake of file sizes, and scaled image quality is not a problem at all.
I did a bunch of reading about why this might be, and I feel like I've tried everything up to this point. So far ive tried:
- Having a background image of only 1920x1080 and scaling it to 10x
- Starting from the 1920x1080 image, resizing it programmatically and drawing this image
- Cutting the background into several segments (I tried a lot of different amounts) and drew only those that are visible in the viewer (I tried this for both small (1080p) and large (10800p) images)
- Using cropped graphics so that only objects on the screen are displayed.
- Double buffering is used both in the picture and in the form in which the camera is located.
- Convert the image upon initialization to an “optimized bitmap” with faster formatting, and then draw the bitmap
I probably tried a couple of other things along with a few optimizations, but it made me forget about everything else for so long. From what I read, most likely, something related to redrawing the controls is too slow for some reason of performance or limitation with Picturebox, however, I can’t say exactly what happens due to the lack of experience in form controls .
Currently, for painting the background in the Paint event, I have either:
g.DrawImage(image, new Rectangle(0, 0, (int)(image.Size.Width * levelScale), (int)(image.Size.Height * levelScale)));
or
g.ScaleTransform(levelScale, levelScale); g.DrawImage(image, new Rectangle(0, 0, (int)(image.Size.Width), (int)(image.Size.Height)));
Where g is the Graphics object.
Did I manage to limit the application capabilities for Win forms, or is there something that I might lose?
Any help is appreciated
Thanks in advance.