[Reprinted] use the GDI + transformation matrix to achieve image translation, scaling, and Rotation

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.