점하고있는 PictureBox에 따라 이미지를 회전 :은 다음과 같이 두 개의 내 양식에 두 점을
*
[^]
[ ]
*
나는 그것이 다음과 같습니다 있도록 포인트와의 PictureBox를 정렬하고 싶은
:
*
\^\
\ \
*
어떻게 각도를 계산하고 PictureBox를 회전시킬 수 있습니까? 현재 내가 이것을 사용하고
: x와 y 값은 절대 때문에
double xDifference = Math.Abs(point2.X - point1.X);
double yDifference = Math.Abs(point2.Y - point1.Y);
double angle = Math.Atan(yDifference/xDifference) * 180/Math.PI;
는하지만 작동하지 않습니다, 그리고 점 2 점 1의 왼쪽 경우, 따라서 그들은 그것을 계산할 수 없습니다.
public Bitmap rotateImage(Image image, PointF offset, float angle) {
// Create a new empty bitmap to hold rotated image
Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
// Make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(rotatedBmp);
// Put the rotation point in the center of the image
g.TranslateTransform(offset.X, offset.Y);
// Rotate the image
g.RotateTransform(angle);
// Move the image back
g.TranslateTransform(-offset.X, -offset.Y);
// Draw passed in image onto graphics object
g.DrawImage(image, new PointF(0, 0));
return rotatedBmp;
}
가 어떻게 그 기능을 사용
: 이미지를 회전하려면, 나는 다음과 같은 기능을 발견? 오프셋 값을 삽입 할 값을 모르겠습니다.감사합니다.
나는 "그림"을 좋아한다. – PiotrWolkowski
먼저 abs를 사용하지 말고'Math.Atan2'를 사용해야합니다. – Vlad
둘째, 어느 지점을 중심으로 회전하고 싶습니까? 이미지의 중심에 대해서는 오프셋이 있어야합니다 ('-image.Width/2, -image.Height/2'). – Vlad