我有两点,A和B.
我需要在 C#中使用一个公式来旋转此图片库两点。
A = *,B = + ,. =图像中心
>image 1
---------------
| * |
| . |
| + |
---------------
>after rotate
---------------
| * + |
| . |
| |
---------------
或
>image 2
---------------
| * |
| . |
| + |
---------------
>after rotate
---------------
| + * |
| . |
| |
---------------
我找到了旋转image 1
的公式,但此公式不适用于image 2
。这个公式是:
float degree = -(float)(Math.Atan2(pointBy - pointAy, pointBx - pointAx) * (180 / Math.PI))
我也使用此功能旋转位图
private Bitmap RotateImage( Bitmap bmp, float angle ) {
Bitmap rotatedImage = new Bitmap( bmp.Width, bmp.Height );
using ( Graphics g = Graphics.FromImage( rotatedImage ) ) {
g.TranslateTransform( bmp.Width / 2, bmp.Height / 2 ); //set the rotation point as the center into the matrix
g.RotateTransform( angle ); //rotate
g.TranslateTransform( -bmp.Width / 2, -bmp.Height / 2 ); //restore rotation point into the matrix
g.DrawImage( bmp, new Point( 0, 0 ) ); //draw the image on the new bitmap
}
return rotatedImage;
}
答案 0 :(得分:0)
我找到了图像2的这个公式
float degree = -(float)(Math.Atan2(pointAy - pointBy, pointAx - pointBx) * (180 / Math.PI));