MFC画眼睛
由于画笔一旦创建后就无法修改。所以要修改画笔的颜色要用DeleteObject()函数将其删除,之后再创建新的画笔例子:换为白色换画笔(画刷)颜色(参考链接:/sunxiving/article/details/51272001)
CBrush brush, *oldBrush;//创建画刷brush.CreateSolidBrush(RGB(0,0,0));//原来为黑色oldBrush=pDC->SelectObject(&brush);pDC->Ellipse(0,0,200,100);//画一个椭圆brush.DeleteObject();//删掉原来brushbrush.CreateSolidBrush(RGB(255, 251, 240));//更改颜色oldBrush=pDC->SelectObject(&brush);//重新选取pDC->Ellipse(50,0,150,100);//再画一个颜色不同的pDC->SelectObject(oldBrush);//还回画刷
只给出OnDraw(CDC* pDC)函数。没有参考代码,尝试自己画一波眼睛简图。
void CJustPaintView::OnDraw(CDC* pDC)//paint an eye{CJustPaintDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereCRect rect;GetClientRect(&rect);pDC->SetMapMode(MM_ANISOTROPIC);pDC->SetWindowExt(rect.Width(), rect.Height());pDC->SetViewportExt(rect.Width(), -rect.Height());pDC->SetViewportOrg(rect.Width()/2, rect.Height()/2);rect.OffsetRect(-rect.Width()/2, -rect.Height()/2);//erweizuobiaoxiCBrush brush, *oldBrush;brush.CreateSolidBrush(RGB(0,0,0));oldBrush=pDC->SelectObject(&brush);pDC->Ellipse(0,0,200,100);brush.DeleteObject();//change color of brushbrush.CreateSolidBrush(RGB(255, 251, 240));oldBrush=pDC->SelectObject(&brush);pDC->Ellipse(50,0,150,100);brush.DeleteObject();//change color of brushbrush.CreateSolidBrush(RGB(0,0,0));oldBrush=pDC->SelectObject(&brush);pDC->Ellipse(50,25,150,75);brush.DeleteObject();//change color of brushbrush.CreateSolidBrush(RGB(255,0,0));oldBrush=pDC->SelectObject(&brush);pDC->Ellipse(75,25,125,75);pDC->SelectObject(oldBrush);}
效果
如果觉得《MFC更换画笔(画刷)颜色以及画眼睛(GDI画图)》对你有帮助,请点赞、收藏,并留下你的观点哦!