使用GDI+ 绘制可旋转的PNG

如果要绘制半透明的图片,请使用.png格式(用photoshop即可轻松制作并处理)
一、首先介绍Graphics的两个函数,
RotateTransform:将整个坐标系逆时针旋转一定角度
TranslateTransform:将整个坐标系偏移到某个位置
本例要实现的功能是在指定位置上旋转图片,首先需要将整个坐标系偏移到指定位置,在进行坐标系的旋转,在函数使用上应先旋转在偏移(与我们想象的相反),代码如下
myGraphics.RotateTransform(angle,MatrixOrderAppend);
myGraphics.TranslateTransform(pnt.x,pnt.y,MatrixOrderAppend);
将图片画在pnt处,图片的中心点在rect1矩形的中心,DrawImage时坐标为图片在原坐标系的坐标减去坐标系的偏移
myGraphics.DrawImage(pImg,- rect1.Width(),- rect1.Height()/2,rect1.Width(), rect1.Height());
myGraphics.ResetTransform();     //将坐标系复位
二、还有一种方法可实现图形的旋转功能,那就是将所绘制的图形放入GraphicsPath中,然后设置图形变换矩阵,例子如下:
Graphics* g;
GraphicsPath myGraphicsPath(FillModeAlternate);
       int offsetrx=m_EllipseData.point1.x -origin.X;
       int offsetry=m_EllipseData.point1 .y -origin.Y;
RectF myRectangle(offsetrx,offsetry ,m_EllipseData.point2.x-m_EllipseData.point1.x,m_EllipseData.point2.y-m_EllipseData.point1 .y    );
 
              myGraphicsPath.AddEllipse (myRectangle);
              Matrix* myPathMatrix=new Matrix();
              myPathMatrix->Rotate(nRotateAngle, MatrixOrderAppend);
              myPathMatrix->Translate(origin.X,origin.Y,MatrixOrderAppend );
              myGraphicsPath.Transform(myPathMatrix);
              g->FillPath(&myBrush, &myGraphicsPath);

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值