更新时间:2015-12-08 10:58:34浏览次数:1+次
新建GDI+单文档工程,加入必要的GDI+代码,看代码:
void C油表View::OnRotatephoto()
{
// TODO: 在此添加命令处理程序代码
Graphics graphics(this->m_hWnd);
this->RedrawWindow();
//////加载图片
Image image(L"cos.jpg");
/////获取当前窗口的中心点
CRect rect;
this->GetClientRect(&rect);
Point center(rect.CenterPoint().x, rect.CenterPoint().y);
int offsetX, offsetY;
offsetX = center.X - image.GetWidth() / 2;
offsetY = center.Y - image.GetHeight() / 2;
//////构造图片显示区域,让图片的中心点与窗口的中心点一致
RectF picRect(offsetX, offsetY, image.GetWidth(), image.GetHeight());
PointF Pcenter = PointF(picRect.X + picRect.Width / 2, picRect.Y + picRect.Height / 2);
////让图片绕中心旋转一周
for (int i = 0; i < 36; i++)
{
////绘图平面以图片的中心点旋转
graphics.TranslateTransform(Pcenter.X, Pcenter.Y);
graphics.RotateTransform(i);
//////恢复绘图平面在水平和垂直方向上的平移
graphics.TranslateTransform(-Pcenter.X, -Pcenter.Y);
///////绘制图片并延时
graphics.DrawImage(&image, picRect);
//Sleep(1000);
///////重置绘图平面的所有变换
graphics.ResetTransform();
}
}
代码实现图:
图片中的锯齿就是图片旋转过程中留下来的。
graphics.TranslateTransform(Pcenter.X, Pcenter.Y);
对于其他的GDI+坐标变换代码,你都是依照这种思路来理解。
相关资讯