Because a project (Packing Box Vector Graphics Editor), after comprehensive evaluation of the actual needs of GDI, GDI +, OpenGL, DirectX and projects, I decided to select GDI + (GDI plus) as a tool for graphic development, since I have never been deeply involved in graphic development before, I was a little confused at the beginning of the project. After some time of exploration, I finally got a little eye off, then we started the following work:
1. How to erase graphics and test the speed of GDI +.
I see a lot on the InternetArticleMost graph Editors Use development tools such as C ++, and then directly call the GDI Windows API for operations. Most graphics are drawn using an exclusive or method, which is fast, however, the drawing is flickering, and the Double Cache mode is also used to prevent the drawing from flashing. However, the speed is a little slow, occupying the memory, while GDI + does not support exclusive or plotting, in Microsoft's technical documents, their reasons are: hardware is becoming more advanced, speed is not a problem, and visual enjoyment is the first. In the future, graphic editors will adopt dual-cache, this is a trend.
1) I searched a lot from other source code websites such as codeproject.Source codeHow to use double cache and mouse operations to erase images? After countless experiments, I finally formed my ownCodeStyle. The general principle is as follows: declare two bitmaps in the memory. One bitmap is used to draw images in time, and the other bitmap is used to store existing images, copy bitmap directly to the graphics corresponding to the drawing window, which can increase the drawing speed.
2) speed testing is quite troublesome. It goes through many times throughout the development process. In my opinion, there are no more than five basic modifications to Object Modeling due to speed problems, in the graphic editor, the speed is not only determined by the mode of GDI + or GDI, but more importantly, the developer selects the appropriate mode based on the development tools you use.Algorithm. The algorithm is generally required. Do not use trigonometric functions, square root, or division. Try to use integers, addition, or multiplication.
An interesting phenomenon found during development is that using a large number of structures also slows down the Data assignment speed, while the class can improve the data assignment speed to a certain extent. But we can see that the point and rectangle provided in. net2.0 are all structured. Why does Microsoft do this? Later, we inserted the relevant information (a person who participated. NET development, and later left Microsoft and attacked. net), Microsoft's. net has a lot of Simple Object API encapsulation, and these. net object implementation is also done in C ++, that is, these tools can call pointers, and my VB. net cannot operate the pointer, so the structure speed is slow. This discovery also led to a lot of work I had to do.
2. Object Modeling.
This is very troublesome. We have been constantly modifying the object model until now, because we have no experience and have taken many detours. I once referred to a vectordraw control, which has a complete object description, metadata, coordinate system, and annotation. After reading it, I was inspired by constant exploration, finally, it forms its own object style. Now this object model can well process the structure of graphics (files, layers, and elements), mouse operation, graphics parameterization, parts, display and operation speed.
1) confirm the element. Generally, basic elements include straight lines, rectangles, (elliptical) circles, (elliptical) arcs, curves, and labels (must be labeled as a designer)
2) Save and process metadata parameters. After several tests, it is found that it is convenient to directly store the pixel value in the parameter of the element. in net2.0, rectangle, point, line and other elements only support the single type. In actual operations, such as scaling, rotation, and coordinate system transformation, the reduction of the single data type is poor, the double type is required for processing. Therefore, I use the double type to process all element parameters. Although it affects the computing performance, the overall speed is acceptable.
3) coordinate system. The device coordinate system in GDI + is a little different from the flute coordinate system we normally use. In order to facilitate users' operations during drawing, we must display the flute Coordinate System on the interface, the device coordinate system is used in actual drawing. Coordinate System objects are also responsible for one-to-one conversion of data in these two coordinate systems.
4) image pickup. Different elements have different optimal pick-up algorithms, such as line segments. How can we judge the mouse line segment? This is very skillful. The algorithm is several dozen times slow and fast, later, I chose the commonly used vector calculation method. It is said that 1 million lines can be judged in one second. This is very good, and so on, and quickly solved the picking algorithm of each element.
Pending