Put all the calculations together.
First of all, the direction of the line connecting the two points can be calculated using
double xDifference = point2.X - point1.X; double yDifference = point2.Y - point1.Y; double angleRadians = Math.Atan2(yDifference, xDifference);
Then the vertical direction (90 degrees) should be parallel to the direction discussed above after the rotation, so the rotation angle
double rotationAngleRadians = angleDegrees - Math.PI/2;
Having this angle, we can calculate the size of the frame:
double newWidth = image.Width * Math.Abs(Math.Cos(rotationAngleRadians)) + image.Height * Math.Abs(Math.Sin(rotationAngleRadians)); double newHeight = image.Width * Math.Abs(Math.Sin(rotationAngleRadians)) + image.Height * Math.Abs(Math.Cos(rotationAngleRadians));
Now we need to first convert so that the middle of the old image is at position 0. This converts the conversion to (-image.Width/2, -image.Height/2) . Then we apply the rotation to rotationAngleDegrees (which is equal to rotationAngleRadians * 180 / Math.PI ), since Graphics ' rotation expects an angle in degrees. Then we move the image in the middle of the new image, which converts the conversion to (newWidth/2, newHeight/2) .
Vlad
source share