MFC GDI绘制哆啦A梦机器猫


下载链接见文末

一、绘图代码

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);

        // 头 直径240
        HBRUSH 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工程)


点击下方"支付宝", ¥100 查看完整内容~ (关于识别码:请任意输入识别码,您记得住就行)

主要代码 // DrawFrogView.cpp : implementation of the CDrawFrogView class // #include "stdafx.h……
2024-06-22
THE END
分享
二维码
打赏
海报
MFC GDI绘制哆啦A梦机器猫
下载链接见文末 一、绘图代码 CPaintDC dc(this); // 用于绘画的设备上下文 CRect rc; GetWindowRect(rc); int cxClient = rc.Widt……
<<上一篇
下一篇>>