【发布时间】:2017-10-15 13:13:48
【问题描述】:
我有两个点,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;
}
【问题讨论】: