GDI+和GDI的一些基本图形描绘方法的对比

本文介绍使用GDI+与GDI进行基本图形绘制的方法,包括清空背景、绘制对角线、网格、圆弧及填充多边形等,并展示了如何设置字体、颜色及画笔宽度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GDI+

GDI

//清空背景

SolidBrush brush(Color(255, 255,255,255));

 

 

 

 

 

 
 

using namespace Gdiplus;

pGraphics->FillRectangle(&brush,0,0,m_winWidth,m_winHeight);

 

//画笔准备

int PenWidth = theApp.m_optionDlg.m_iSliderPenWidth;

Pen pen(Color(255, 0, 0, 255), PenWidth);

Pen pen2(Color(255, 255, 0, 0), PenWidth);

 

 

 

 

 

//-------------------------------------------

//画对角线

pGraphics->DrawLine(&pen,pRect->left,pRect->top,pRect->right, pRect->bottom);

pGraphics->DrawLine(&pen,pRect->right,pRect->top,pRect->left, pRect->bottom);

 

//-------------------------------------------

//画格子

for (int y = 0; y < m_winHeight; y += 10) {

    pGraphics->DrawLine(&pen, 0, y, m_winWidth, y);

}

 

for (int x = 0; x < m_winWidth; x += 10) {

    pGraphics->DrawLine(&pen, x, 0, x, m_winHeight);

}

 

 

 

 

//-------------------------------------------

//画圆弧

pGraphics->DrawArc(&pen2, 0,0, 100,100, 0.0f,360.0f);

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

//-------------------------------------------

//画填充多边形

SolidBrush fillPolyBrush(Color(128, 255, 0, 0));

Point point1(100, 100);

Point point2(200, 130);

Point point3(250, 160);

Point point4(150, 200);

Point point5( 70, 130);

Point points[5] = {point1, point2, point3, point4, point5};

pGraphics->FillPolygon(&fillPolyBrush, points, 5);

 

 

 

 

 

 

//-------------------------------------------

//字符串

if (theApp.m_optionDlg.m_strDrawString != "") {

// UNICODE字串变换

_bstr_t bstr(theApp.m_optionDlg.m_strDrawString);

 

Font myFont(L"Arial", 42);

PointF origin(0.0f, 0.0f);

 

 

 

 

SolidBrush blackBrush(Color(255, 0, 0, 0));

StringFormat format;

format.SetAlignment(StringAlignmentCenter);

 

 

pGraphics->DrawString(

bstr,

bstr.length(),

&myFont,

origin,

&blackBrush);

}

//清空背景

CBrush brush;

brush.CreateSolidBrush(RGB(255, 255, 255)); 

//初始画刷保存

CBrush OrigBrush;

CBrush *pTmpBrush = (CBrush*)pDC->SelectObject(brush);

OrigBrush.FromHandle((HBRUSH)pTmpBrush);

 

pDC->Rectangle(pRect);

pDC->SelectObject(&OrigBrush);

brush.DeleteObject();

        

//画笔准备

int PenWidth = theApp.m_optionDlg.m_iSliderPenWidth;

CPen pen(PS_SOLID, PenWidth, RGB(0, 0, 255));

CPen pen2(PS_SOLID, PenWidth, RGB(255, 0, 0));

//初始画笔保存

CPen OrigPen;

CPen *pTmpPen = (CPen*)pDC->SelectObject(pen);

OrigPen.FromHandle((HPEN)pTmpPen);

 

//-------------------------------------------

//画笔准备

pDC->MoveTo(pRect->left, pRect->top);

pDC->LineTo(pRect->right, pRect->bottom);

pDC->MoveTo(pRect->right, pRect->top);

pDC->LineTo(pRect->left, pRect->bottom);

 

//-------------------------------------------

//画格子

for (int y = 0; y < m_winHeight; y += 10) {

pDC->MoveTo(0, y);

pDC->LineTo(m_winWidth, y);

}

for (int x = 0; x < m_winWidth; x += 10) {

pDC->MoveTo(x, 0);

pDC->LineTo(x, m_winHeight);

}

pDC->SelectObject(&OrigPen);

pen.DeleteObject();        

 

//-------------------------------------------

//画圆弧

long width, height;

POINT    cpos;

double   r,srad,erad;

const double m_pi = 3.1415926535758932;

 

width = 100 - 0;

height = 100 - 0;

cpos.x = 0 + (long)(width / 2.0);

cpos.y = 0 + (long)(height / 2.0);

r = max(width / 2.0, height / 2.0);

srad = 0.0 * m_pi / 180.0;

erad = (0.0 + 360.0) * m_pi / 180.0;

pTmpPen = (CPen*)pDC->SelectObject(pen2);

pDC->Arc(0,0, 100,100,

cpos.x + (long)(r * cos(srad)),

cpos.y + (long)(r * sin(srad)),        

cpos.x + (long)(r * cos(erad)),

cpos.y + (long)(r * sin(erad)));

pDC->SelectObject(&OrigPen);

pen2.DeleteObject();       

 

 

 

//-------------------------------------------

//画填充多边形

CBrush fillPolyBrush;

fillPolyBrush.CreateSolidBrush(RGB(255, 0, 0)); 

pTmpBrush = (CBrush*)pDC->SelectObject(fillPolyBrush);

CPoint point1(100, 100);

CPoint point2(200, 130);

CPoint point3(250, 160);

CPoint point4(150, 200);

CPoint point5( 70, 130);

CPoint points[5] = {point1, point2, point3, point4, point5};

pDC->Polygon(points, 5);

pDC->SelectObject(&OrigBrush);

fillPolyBrush.DeleteObject();

 

//-------------------------------------------

//符串

if (theApp.m_optionDlg.m_strDrawString != "") {

//UNICODE字串变换

_bstr_t bstr(theApp.m_optionDlg.m_strDrawString);

 

CFont myFont;

CFont OrigFont;

myFont.CreatePointFont(420, "Arial");

CFont *pTmpFont = (CFont*)pDC->SelectObject(myFont);

OrigFont.FromHandle((HFONT)pTmpFont);

                  

CBrush blackBrush;

blackBrush.CreateSolidBrush(RGB(0, 0, 0)); 

pTmpBrush = (CBrush*)pDC->SelectObject(blackBrush);

//pDC->SetTextAlign(TA_CENTER);

 

pDC->TextOut(0, 0, bstr, bstr.length());

pDC->SelectObject(&OrigFont);

myFont.DeleteObject();

}

 
内容概要:本文介绍了基于Python实现的SSA-GRU(麻雀搜索算法优化门控循环单元)时间序列预测项目。项目旨在通过结合SSA的全局搜索能力GRU的时序信息处理能力,提升时间序列预测的精度效率。文中详细描述了项目的背景、目标、挑战及解决方案,涵盖了从数据预处理到模型训练、优化及评估的全流程。SSA用于优化GRU的超参数,如隐藏层单元数、学习率等,以解决传统方法难以捕捉复杂非线性关系的问题。项目还提供了具体的代码示例,包括GRU模型的定义、训练验证过程,以及SSA的种群初始化、迭代更新策略适应度评估函数。; 适合人群:具备一定编程基础,特别是对时间序列预测深度学习有一定了解的研究人员技术开发者。; 使用场景及目标:①提高时间序列预测的精度效率,适用于金融市场分析、气象预报、工业设备故障诊断等领域;②解决传统方法难以捕捉复杂非线性关系的问题;③通过自动化参数优化,减少人工干预,提升模型开发效率;④增强模型在不同数据集未知环境中的泛化能力。; 阅读建议:由于项目涉及深度学习智能优化算法的结合,建议读者在阅读过程中结合代码示例进行实践,理解SSAGRU的工作原理及其在时间序列预测中的具体应用。同时,关注数据预处理、模型训练优化的每个步骤,以确保对整个流程有全面的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值