Rotate an Image Around a Pivot (Anchor) GDI+

I still love using WinForms...
so here is some C# code to rotate an image around an anchor (pivot point) using GDI+

private void DrawRotatedAtPivot(Graphics g, Image image, Point imageLocation, PointF pivot, int angle)
{
    Matrix matrix = new Matrix();
    matrix.RotateAt(angle, imageLocation);
    g.Transform = matrix;
    g.DrawImage(image, (int)(imageLocation.X - image.Width * pivot.X), (int)(imageLocation.Y - image.Height * pivot.Y));
    g.ResetTransform();
}


Note: pivot of (0.5f, 0.5f ) is center of the image

Comments