The current CPU is very fast, in fact, the mathematical computing is generally very fast, the CPU is processing the drawing most of the time, and the drawing has three realms: 1> Each redraw the overall invalidate (); 2> invalidate (rect) is drawn locally each time. 3> selected partial painting is available.
It cannot be said that the third method is good, depending on the situation, the realm is highProgramIt must be complicated. If the requirement on efficiency is not high or the drawing volume is small, the first method is used directly. However, the first and second ways of drawing programs with a little expertise certainly cannot meet the requirements, and the third method must be used. However, the third method has a variety of methods and needs to be addressed based on the actual situation. Here we will explain three common methods that can be used together.
1. cache-bitmap or doublebuffer. Cache is to first draw the drawn image to a memory bitmap, And Then paste the bitmap at one time, it can increase the drawing speed, but also avoid blinking. Doublebuffer = true is the C # form attribute. If this attribute is set, it is estimated that the system will use the memory bitmap cache in the invalid zone instead of being processed by the programmer bitmap.
2. make proper use of invalid regions. The invalid region is the region in which the system saves the changes and needs to be re-painted. It can be directly obtained in onpaint (), E. cliprectangle, or in other ways. Windows only redraws the drawing information in the invalid area. HoweverCodeGenerally, the entire area is drawn. In many cases, the invalid area is only a small part of the area. Although all the drawing code is executed, the Windows system only updates the drawing in the invalid area. There are two usage points: 1> when a user requests re-painting, only the user requests to re-paint the specified region, rather than the entire region, such as invalidate (rect ); 2> drawing code graphics g; G. drawline \ G. drawstring \ G. fillrectangle... first, determine whether the drawing content is in the invalid area, if not directly G. draw... drawing code.
3. Direct texture. Generally, drawing or redrawing is performed in Windows based on the invalid area. If you need to re-paint when moving the mouse, you can use the Windows system to process the paint message, sometimes it cannot meet the requirements, for example, ① when you move the mouse to draw a cross measurement line, you have to use a line or line instead of a paint message. For example, ② when you move the mouse to draw a prompt box that follows the information, you need to frequently erase the background of the previous coverage, for example, ③ relationship between billiards and the background of the table during billiards rolling. How can we solve these problems? First of all, you must not use the original drawing mechanism of windows. One of the solutions is to constantly change the area between frames and paste the memory bitmap. The information box in ② can be re-uploaded every time the mouse position changes. draw... or paste the previously generated information box memory bitmap. ② the background covered by the information box should intercept the original large background. The location and size bitmap of the erased area should be pasted back to erase the background. Every time a large background changes, the large background memory bitmap should be generated again, so it can be the background of the change.
These three methods can be used together to solve the efficiency problem of medium drawing projects. For a large or medium-sized drawing, remember two points: 1. Draw only the part that can be displayed on the computer screen; 2. Draw only the changed part.