【问题标题】:Rotate image from B point to A point将图像从 B 点旋转到 A 点
【发布时间】: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;
}

https://stackoverflow.com/a/12025915/5220303

【问题讨论】:

    标签: c# math graphics


    【解决方案1】:

    我找到了图像 2 的这个公式

    float degree = -(float)(Math.Atan2(pointAy - pointBy, pointAx - pointBx) * (180 / Math.PI));

    【讨论】:

      猜你喜欢
      • 2011-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      • 1970-01-01
      相关资源
      最近更新 更多