Recently, a buddy asked me about the problem of GDI + image rotation. I searched the internet and saw this article in our blog garden,
Source: http://www.cnblogs.com/XieKe-cs01/archive/2006/03/09/346771.html
during this period, we used GDI + to develop a certain amount of graphic rendering software, similar to coredraw, for teaching purposes. At the beginning, we used the matrix provided by GDI + to implement image rotation and transformation. The translation and scaling of images were calculated by ourselves. Later, it was found that after the coordinate value is modified through calculation, the image will be deformed after being scaled multiple times, especially after being scaled down to a very small scale and cannot be restored. Therefore, I wanted to use matrix to achieve image flattening and scaling. I thought it was very simple because there were ready-made interfaces and I didn't expect it to be much harder to implement.
after using matrix, scale the image first and then rotate it. Everything works normally and the effect is good. However, the image is rotated first and then scaled. The problem is that the image is drifting on the drawing page. This is strange. What are the differences between operations? During the painting, I strictly followed the first translation, then the scaling, and finally completed the rotation order?
debugging found that the rotation center of the image is not changed after first Scaling (the coordinate in the upper left corner is used as the zoom base point, and the image center is used as the rotate base point), but the image is scaled after rotation, the rotation center of the image is constantly changing, so the position of the entire image is offset after matrix transformation. For example:
Figure 1 differences between scaling and rotating in different order
what should I do? If you want to do this, you can only offset the image back When zooming, so that the central point of the image can be fixed at a certain position.
the algorithm is as follows:
The following transform matrix is set during drawing: