您的位置:首页 > 科技 > 能源 > MFC绘制哆啦A梦

MFC绘制哆啦A梦

2024/12/27 14:31:29 来源:https://blog.csdn.net/wang161019/article/details/139775905  浏览:    关键词:MFC绘制哆啦A梦

文章目录

    • OnPaint绘制代码
    • 完整Visual Studio工程下载
    • 其他卡通人物绘制

在这里插入图片描述

OnPaint绘制代码

		CPaintDC dc(this); // 用于绘画的设备上下文CRect rc;GetWindowRect(rc);int cxClient = rc.Width();int cyClient = rc.Height();// 辅助线HPEN hPen = CreatePen(PS_DOT, 1, RGB(192, 192, 192));HPEN hOldPen = (HPEN)SelectObject(dc, hPen);MoveToEx(dc, cxClient / 2, 0, NULL);LineTo(dc, cxClient / 2, cyClient);MoveToEx(dc, 0, cyClient / 2, NULL);LineTo(dc, cxClient, cyClient / 2);SelectObject(dc, hOldPen);// 头 直径240HBRUSH hBlueBrush = CreateSolidBrush(RGB(0, 159, 232));HBRUSH hOldBrush = (HBRUSH)SelectObject(dc, hBlueBrush);DrawEllipse(&dc, cxClient / 2 - 120, cyClient / 2 - 200, cxClient / 2 + 120, cyClient / 2 + 40,RGB(0, 0, 0), RGB(0, 159, 232));SelectObject(dc, hOldBrush);// 脸 直径200 DrawEllipse(&dc, cxClient / 2 - 100, cyClient / 2 - 160, cxClient / 2 + 100, cyClient / 2 + 40,RGB(0,0,0), RGB(255,255,255));//眼睛hOldBrush = DrawEyes(hOldBrush, dc, cxClient, cyClient);// 鼻子HBRUSH hRedBrush = CreateSolidBrush(RGB(255, 0, 0));hOldBrush = (HBRUSH)SelectObject(dc, hRedBrush);DrawEllipse(&dc, cxClient / 2 - 10, cyClient / 2 - 135, cxClient / 2 + 10, cyClient / 2 - 115,RGB(0, 0, 0), RGB(255, 0, 0));SelectObject(dc, hOldBrush);MoveToEx(dc, cxClient / 2, cyClient / 2 - 115, NULL);LineTo(dc, cxClient / 2, cyClient / 2 - 30);// 嘴巴Arc(dc, cxClient / 2 - 70, cyClient / 2 - 120, cxClient / 2 + 70, cyClient / 2 - 30,cxClient / 2 - 60, cyClient / 2 - 50, cxClient / 2 + 60, cyClient / 2 - 50);// 胡须  中上下DrawBeard(dc, cxClient, cyClient);// 身体hOldBrush = (HBRUSH)SelectObject(dc, hBlueBrush);Rectangle(dc, cxClient / 2 - 100, cyClient / 2 - 10, cxClient / 2 + 100, cyClient / 2 + 150);SelectObject(dc, hOldBrush);// 肚皮Ellipse(dc, cxClient / 2 - 70, cyClient / 2 - 20, cxClient / 2 + 70, cyClient / 2 + 120); // 圆hPen = CreatePen(PS_DOT, 1, RGB(255, 255, 255)); // 擦除肚皮上面嘴巴下面的圆弧hOldPen = (HPEN)SelectObject(dc, hPen);Arc(dc, cxClient / 2 - 70, cyClient / 2 - 20, cxClient / 2 + 70, cyClient / 2 + 120,cxClient / 2 + 60, cyClient / 2 - 10, cxClient / 2 - 60, cyClient / 2 - 10);SelectObject(dc, hOldPen);// 围脖hOldBrush = (HBRUSH)SelectObject(dc, hRedBrush);RoundRect(dc, cxClient / 2 - 102, cyClient / 2 - 12, cxClient / 2 + 102, cyClient / 2 + 5, 20, 20);SelectObject(dc, hOldBrush);// 铃铛HBRUSH hYellowBrush = CreateSolidBrush(RGB(255, 255, 0));hOldBrush = (HBRUSH)SelectObject(dc, hYellowBrush);Ellipse(dc, cxClient / 2 - 12, cyClient / 2 - 4, cxClient / 2 + 12, cyClient / 2 + 20);RoundRect(dc, cxClient / 2 - 12, cyClient / 2 + 3, cxClient / 2 + 12, cyClient / 2 + 6, 20, 20);SelectObject(dc, hRedBrush);Ellipse(dc, cxClient / 2 - 5, cyClient / 2 + 8, cxClient / 2 + 5, cyClient / 2 + 18);SelectObject(dc, hOldBrush);// 裤腿Ellipse(dc, cxClient / 2 - 20, cyClient / 2 + 130, cxClient / 2 + 20, cyClient / 2 + 170); // 画圆hPen = CreatePen(PS_DOT, 1, RGB(255, 255, 255)); // 擦除肚皮下面嘴巴上面的圆弧hOldPen = (HPEN)SelectObject(dc, hPen);Arc(dc, cxClient / 2 - 20, cyClient / 2 + 130, cxClient / 2 + 20, cyClient / 2 + 170,cxClient / 2 - 20, cyClient / 2 + 150, cxClient / 2 + 20, cyClient / 2 + 150);SelectObject(dc, hOldPen);// 口袋Pie(dc, cxClient / 2 - 50, cyClient / 2, cxClient / 2 + 50, cyClient / 2 + 100,cxClient / 2 - 50, cyClient / 2 + 50, cxClient / 2 + 50, cyClient / 2 + 50);// 脚掌Ellipse(dc, cxClient / 2 - 110, cyClient / 2 + 135, cxClient / 2 - 10, cyClient / 2 + 165);Ellipse(dc, cxClient / 2 + 10, cyClient / 2 + 135, cxClient / 2 + 110, cyClient / 2 + 165);// 胳膊POINT apt[4];hOldBrush = (HBRUSH)SelectObject(dc, hBlueBrush);apt[0].x = cxClient / 2 - 100;apt[0].y = cyClient / 2;apt[1].x = cxClient / 2 - 150;apt[1].y = cyClient / 2 + 60;apt[2].x = cxClient / 2 - 140;apt[2].y = cyClient / 2 + 80;apt[3].x = cxClient / 2 - 100;apt[3].y = cyClient / 2 + 60;Polygon(dc, apt, 4);SelectObject(dc, hOldBrush);Ellipse(dc, cxClient / 2 - 168, cyClient / 2 + 60, cxClient / 2 - 138, cyClient / 2 + 90); // 左手掌hOldBrush = (HBRUSH)SelectObject(dc, hBlueBrush);apt[0].x = cxClient / 2 + 100;apt[0].y = cyClient / 2;apt[1].x = cxClient / 2 + 150;apt[1].y = cyClient / 2 + 60;apt[2].x = cxClient / 2 + 140;apt[2].y = cyClient / 2 + 80;apt[3].x = cxClient / 2 + 100;apt[3].y = cyClient / 2 + 60;Polygon(dc, apt, 4);SelectObject(dc, hOldBrush);Ellipse(dc, cxClient / 2 + 168, cyClient / 2 + 60, cxClient / 2 + 138, cyClient / 2 + 90); // 右手掌// 		// 左手举着小风车
// 		MoveToEx(dc, cxClient / 2 - 160, cyClient / 2 + 62, NULL);
// 		LineTo(dc, cxClient / 2 - 160, cyClient / 2 - 40);
// 		DrawWindmill(dc, cxClient / 2 - 160, cyClient / 2 - 40);
// 
// 		// 右手举着小风车
// 		MoveToEx(dc, cxClient / 2 + 160, cyClient / 2 + 62, NULL);
// 		LineTo(dc, cxClient / 2 + 160, cyClient / 2 - 40);
// 		DrawWindmill(dc, cxClient / 2 + 160, cyClient / 2 - 40);// 左手举着五星红旗MoveToEx(dc, cxClient / 2 - 160, cyClient / 2 + 62, NULL);LineTo(dc, cxClient / 2 - 160, cyClient / 2 - 40);DrawFlagChina(dc, cxClient / 2 - 160+1, cyClient / 2 - 40);// 右手举着奥运五环旗MoveToEx(dc, cxClient / 2 + 160, cyClient / 2 + 62, NULL);LineTo(dc, cxClient / 2 + 160, cyClient / 2 - 40);DrawFlagOlympics(dc, cxClient / 2 + 160, cyClient / 2 - 40);// 去多余线,增强立体感hPen = CreatePen(PS_SOLID, 2, RGB(0, 159, 232));hOldPen = (HPEN)SelectObject(dc, hPen);MoveToEx(dc, cxClient / 2 - 100, cyClient / 2, NULL);LineTo(dc, cxClient / 2 - 100, cyClient / 2 + 50);MoveToEx(dc, cxClient / 2 + 100, cyClient / 2, NULL);LineTo(dc, cxClient / 2 + 100, cyClient / 2 + 50);SelectObject(dc, hOldPen);// 清理资源DeleteObject(hPen);DeleteObject(hBlueBrush);DeleteObject(hRedBrush);DeleteObject(hYellowBrush);

完整Visual Studio工程下载

点击前往下载

其他卡通人物绘制

https://blog.csdn.net/wang161019/article/details/139872513
点击前往下载
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com