利用GdiPlus::Matrix实现图形旋转

利用GdiPlus::Matrix实现图形旋转
用Gdiplus::Matrix对图形进行简单的旋转,可以免除繁琐的数学计算。
这里主要用到了Gdiplus::Matrix::RotateAt和Gdiplus::Graphics::SetTransForm实现图形旋转。

1、类GdiPlus::Matrix的RotateAt方法,原型如下:
Status RotateAt( REAL angle,
     const PointF &center,
    MatrixOrder order
);
参数angle为需要旋转的角度,center为旋转的中心,order为旋转Matrix的顺序。order的取值有两个:Gdiplus::MatrixOrderPrepend和Gdiplus::MatrixOrderAppend,默认取值为Gdiplus::MatrixOrderPrepend。

2、类Gdiplus::Graphics的SetTransForm方法,原型如下:
Status SetTransform(  const Matrix *matrix
);
参数matrix就是上面的Gdiplus::Matrix对象指针。

示例代码如下:
VOID Example_Rotate(HDC hdc)
{
   Gdiplus::Graphics graphics(hdc);
   Gdiplus::Pen pen(Color(255, 0, 0, 255));
   Gdiplus::Matrix matrix;
   Gdiplus::PonitF P(50, 50);              //  旋转中心
   matrix.RotateAt(100.0f, P);                //  旋转100度
   graphics.SetTransform(&matrix);
   graphics.DrawEllipse(&pen, 0, 0, 100, 50); 
}

效果展示:
利用GdiPlus::Matrix实现图形旋转_第1张图片

参考资料:MSDN

你可能感兴趣的:(利用GdiPlus::Matrix实现图形旋转)