There are overloads of Graphics.DrawImage that take an array of three points used to define a parallelogram for the destination, for example:
Notes
The destPoints parameter indicates three points of the parallelogram. the three point structures are the upper left, upper right, and lower left corners of the parallelogram. The fourth paragraph is extrapolated from the first three to form a parallelogram.
The image represented by the image parameter is scaled and shifted to fit the parallelogram shape specified by the destPoints parameters.
MSDN also has an article describing the use of this method: How to rotate, flip, and skew images using the following code example. Unfortunately, this example complicates the problem, also distorting the image.
Point[] destinationPoints = { new Point(200, 20), // destination for upper-left point of original new Point(110, 100), // destination for upper-right point of original new Point(250, 30)}; // destination for lower-left point of original Image image = new Bitmap("Stripes.bmp"); // Draw the image unaltered with its upper-left corner at (0, 0). e.Graphics.DrawImage(image, 0, 0); // Draw the image mapped to the parallelogram. e.Graphics.DrawImage(image, destinationPoints);
The main differences compared to using the Graphics.Transform property:
- This method does not allow you to specify the angle of rotation in degrees - you need to use simple trigonometry to obtain points.
- This conversion applies only to a specific image.
- Well, if you only need to draw one rotated image, and everything else does not rotate, because after that you do not have to reset
Graphics.Transform . - It’s bad if you want to rotate several things together (ie rotate the “camera”).
Justin
source share