【WIN32开发】GDI+基础

画线/边框(Pen)

 

1、画单线-------DrawLine

Pen pen(Color(255,0,0,0),3);  
PointF L_PTStart(0,0);  
PointF L_PTEnd(100,10);  
graphics.DrawLine(&pen,L_PTStart,L_PTEnd);  

 

2、连接线--------DrawLines

 

Pen blackPen(Color(255, 0, 0, 0), 3);  
  
PointF point1(10.0f, 10.0f);  
PointF point2(10.0f, 100.0f);  
PointF point3(200.0f, 50.0f);  
PointF point4(250.0f, 80.0f);  
  
PointF points[4] = {point1, point2, point3, point4};  
PointF* pPoints = points;  
  
graphics.DrawLines(&blackPen, pPoints, 4);  

 

解说:points数组中的每一个点都是连接线上的转折点,DrawLines会把它们依照顺序一个个连接起来


3、画矩形-----DrawRectangle,仅仅画边框。不画背景色

Pen blackPen(Color(255,255, 0, 0), 3);  
Rect rect(0, 0, 100, 100);  
graphics.DrawRectangle(&blackPen, rect);  

 

4、一次画多个矩形----DrawRectangles

Pen blackPen(Color(255, 0, 255, 0), 3);  
// 定义三个矩形  
RectF rect1(0.0f, 0.0f, 50.0f, 60.0f);  
RectF rect2(60.0f, 70.0f, 70.0f, 100.0f);  
RectF rect3(100.0f, 0.0f, 50.0f, 50.0f);  
RectF rects[] = {rect1, rect2, rect3};  
//RectF是对Rect的封装  
graphics.DrawRectangles(&blackPen, rects, 3);  


5、画曲线-----DrawCurve(不推荐使用,挡曲线弯曲角度非常小的时候这个函数就会捣乱,只有角度较大时推荐使用

Pen greenPen(Color::Green, 3);  
PointF point1(100.0f, 100.0f);  
PointF point2(200.0f, 50.0f);  
PointF point3(400.0f, 10.0f);  
PointF point4(500.0f, 100.0f);  
  
PointF curvePoints[4] = {  
    point1,  
    point2,  
    point3,  
    point4};  
  
    PointF* pcurvePoints = curvePoints;  
  
    // 画曲线  
    graphics.DrawCurve(&greenPen, curvePoints, 4);  
  
    //画连接点和直线连接线  
    SolidBrush redBrush(Color::Red);  
    graphics.FillEllipse(&redBrush, Rect(95, 95, 10, 10));//画连接点  
    graphics.FillEllipse(&redBrush, Rect(195, 45, 10, 10));  
    graphics.FillEllipse(&redBrush, Rect(395, 5, 10, 10));  
    graphics.FillEllipse(&redBrush, Rect(495, 95, 10, 10));  
  
    Pen redPen(Color::Red, 2);  
    graphics.DrawLines(&redPen,curvePoints,4);//画连接线  

注意:这里为了比較画曲线与画直线连接线的差别。我用绿色画的曲线,用红色画的直线连接线。同一时候画出了连接点,大家能够比較一下。

6、画闭合曲线

Pen greenPen(Color::Green, 3);  
PointF point1(100.0f, 100.0f);//開始点  
PointF point2(200.0f, 50.0f);  
PointF point3(400.0f, 10.0f);  
PointF point4(500.0f, 100.0f);  
PointF point5(600.0f, 200.0f);  
PointF point6(700.0f, 400.0f);  
PointF point7(500.0f, 500.0f);//结束点  
  
PointF curvePoints[7] = {  
    point1,  
    point2,  
    point3,  
    point4,  
    point5,  
    point6,  
    point7};  
  
    PointF* pcurvePoints = curvePoints;  
  
    //画闭合曲线  
    graphics.DrawClosedCurve(&greenPen, curvePoints, 7);  
  
    //画连接点  
    SolidBrush redBrush(Color::Red);  
    SolidBrush startBrush(Color::Blue);  
    SolidBrush endBrush(Color::Black);  
    graphics.FillEllipse(&startBrush, Rect(95, 95, 10, 10));  
    graphics.FillEllipse(&redBrush, Rect(495, 95, 10, 10));  
    graphics.FillEllipse(&redBrush, Rect(195, 45, 10, 10));  
    graphics.FillEllipse(&redBrush, Rect(395, 5, 10, 10));  
    graphics.FillEllipse(&redBrush, Rect(595, 195, 10, 10));  
    graphics.FillEllipse(&redBrush, Rect(695, 395, 10, 10));  
    graphics.FillEllipse(&endBrush, Rect(495, 495, 10, 10));  

 

注意:蓝色点是開始点,黑色点是结束点
7、画多边形-----DrawPolygon,既然能画闭合的曲线。肯定也有闭合的直线。当然闭合的直线也就是所谓的多边形

推荐使用,绘制的曲线夹角非常小时都能完成呈现效果

Pen blackPen(Color(255, 0, 0, 0), 3);  
//创建点数组,DrawPolygon会按这些点的顺序逐个连接起来  
PointF point1(100.0f, 100.0f);  
PointF point2(200.0f, 130.0f);  
PointF point3(150.0f, 200.0f);  
PointF point4(50.0f, 200.0f);  
PointF point5(0.0f, 130.0f);  
PointF points[5] = {point1, point2, point3, point4, point5};  
PointF* pPoints = points;  
// 画多边形,也就是闭合直线  
graphics.DrawPolygon(&blackPen, pPoints, 5);  

8、画弧线----DrawArc

Pen redPen(Color::Red, 3);  
RectF ellipseRect(0, 0, 200, 100);  
REAL startAngle = 0.0f;//起始度数  
REAL sweepAngle = 90.0f;//结尾时的度数  
// 画弧线  
graphics.DrawArc(&redPen, ellipseRect, startAngle, sweepAngle);  
//画出边框,做为參考  
Pen greenPen(Color::Green, 1);  
graphics.DrawRectangle(&greenPen,ellipseRect);  

 

9、画扇形----DrawPie

Pen blackPen(Color(255, 0, 255, 0), 3);  
  
// 定义椭圆。然后在里面截一部分作为终于的扇形  
RectF ellipseRect(0, 0, 200, 100);  
REAL startAngle = 40.0f;  
REAL sweepAngle = 100.0f;  
  
//画扇形  
graphics.DrawPie(&blackPen, ellipseRect, startAngle, sweepAngle);  

先出效果图:

 

这里要对它两上名词解说一下,什么叫startAngle(開始度数),什么叫sweepAngle(范围度数也能叫扫过度数,我译的。嘿嘿)

看下MSDN里对DrawPie函数的解说就会懂了,里面有这个图,给大家看一下

 

填充区域(SolidBrush)

1、填充闭合区域----FillClosedCurve,边框相应:DrawClosedCurve(推荐使用FillPolygon填充多边形

SolidBrush blackBrush(Color(255, 0, 0, 0));  
  
PointF point1(100.0f, 100.0f);  
PointF point2(200.0f, 50.0f);  
PointF point3(250.0f, 200.0f);  
PointF point4(50.0f, 150.0f);  
PointF points[4] = {point1, point2, point3, point4};  
  
//填充闭合区域  
graphics.FillClosedCurve(&blackBrush, points, 4);  
//为闭合区域画边框  
Pen curPen(Color::Green,3);  
graphics.DrawClosedCurve(&curPen,points,4);  

 

注意:从结果图中也能够看出填充区域(背景)和边框是分离的,用FillClosedCurve来填充背景色,用DrawClosedCurve来画边框

2、填充椭圆---FillEllipse。边框相应:DrawEllipse

SolidBrush blackBrush(Color(255, 0, 0, 0));  
RectF ellipseRect(0.0f, 0.6f, 200.8f, 100.9f);  
//填充椭圆  
graphics.FillEllipse(&blackBrush, ellipseRect);  
//画边框,当然也能够不画  
Pen borderPen(Color::Green,3);  
graphics.DrawEllipse(&borderPen,ellipseRect);  

还有类似的几个函数。这里就不一 一解说了

它们是:

FillPie(Brush* brush, RectF& rect, REAL startAngle, REAL sweepAngle)    //填充扇形,相应DrawPie  
  
FillPolygon(Brush* brush, PointF* points, INT count)                       //填充多边形。相应DrawPolygon  
  
FillRectangle(Brush* brush, RectF& rect)                                          //填充矩形,相应DrawRectangle  
  
FillRectangles(Brush* brush, RectF* rects, INT count)                   //同一时候填充多个矩形。相应DrawRectangles 

还有是关于路径和区域的,先记下,后面再说

Status FillPath( const Brush* brush, const GraphicsPath*path);  
  
Status FillRegion( const Brush* brush, const Region*region);  

写字(SolidBrush)

 

形式一:Status DrawString( const WCHAR*string, INTlength, const Font* font, const PointF&origin, const Brush*brush);

Graphics graphics(this->GetDC()->m_hDC);  
  
SolidBrush brush(Color(255,0,0,255));  
  
FontFamily fontfamily(L"宋体");  
Font font(&fontfamily,24,FontStyleRegular,UnitPixel);  
  
PointF  pointf(0,0);//PointF类对点进行了封装。这里是指定写字的開始点  
  
graphics.DrawString(L"GDI写字",-1,&font,pointf,&brush);  
//DrawString还有另外两个重载形式,能实现更强大的功能  

形式二:Status DrawString( const WCHAR*string, INT length, const Font*font, const RectF&layoutRect, const StringFormat*stringFormat, const Brush*brush);

WCHAR string[256];  
wcscpy(string, L"Sample Text");  
  
// Initialize arguments.  
Font myFont(L"Arial", 16);//字体  
RectF layoutRect(0.0f, 0.0f, 200.0f, 50.0f);//矩形  
  
//设定字体格式  
StringFormat format;  
format.SetAlignment(StringAlignmentCenter); //水平方向的对齐方式,这里设置为水平居中  
format.SetLineAlignment(StringAlignmentFar);//垂直方向的对齐方式,这里设置为垂直居下  
SolidBrush blackBrush(Color(255, 0, 0, 0));  
  
//画矩形边框  
graphics.DrawRectangle(&Pen(Color::Green, 3), layoutRect);  
//填充矩形背景  
graphics.FillRectangle(&SolidBrush(Color(255,255,0,0)),layoutRect);  
//DrawString,一定要先画背景再写字,要不然,字会被背景覆盖  
graphics.DrawString(  
    string,  
    wcslen(string),  
    &myFont,  
    layoutRect,  
    &format,  
    &blackBrush);  

形式三:Status DrawString( const WCHAR*string, INTlength, const Font* font, const PointF&origin, const StringFormat*stringFormat, const Brush* brush);

这样的形式是形式一与形式二的结合,指定写字開始点和字体格式,这里就不举例了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数据来源:中经数据库 主要指标110多个(全部都是纯粹的 市辖区 指标),大致是: GDP GDP增速 第一产业增加值占GDP比重 第二产业增加值占GDP比重 第三产业增加值占GDP比重 人均GDP 社会消费品零售总额 固定资产投资(不含农户) 新设外商投资企业数_外商直接投资 实际利用外资金额(美元) 一般公共预算收入 一般公共预算支出 一般公共预算支出_教育 一般公共预算支出_科学技术 金融机构人民币各项存款余额_个人储蓄存款 金融机构人民币各项存款余额 金融机构人民币各项贷款余额 规模以上工业企业单位数 规模以上工业企业单位数_内资企业 规模以上工业企业单位数_港澳台商投资企业 规模以上工业企业单位数_外商投资企业 规模以上工业总产值 规模以上工业总产值_内资企业 规模以上工业总产值_港澳台商投资企业 规模以上工业总产值_外商投资企业 规模以上工业企业流动资产合计 规模以上工业企业固定资产合计 规模以上工业企业利润总额 规模以上工业企业应交增值税 规模以上工业企业主营业务税金及附加 户籍人口数 年均户籍人口数 户籍人口自然增长率 第一产业就业人员占全部城镇单位就业人员比重 第二产业就业人员占全部城镇单位就业人员比重 第三产业就业人员占全部城镇单位就业人员比重 城镇非私营单位就业人员数 城镇非私营单位就业人员数_第一产业 城镇非私营单位就业人员数_第二产业 城镇非私营单位就业人员数_第三产业 城镇非私营单位就业人员数_农、林、牧、渔业 城镇非私营单位就业人员数_采矿业 城镇非私营单位就业人员数_制造业 城镇非私营单位就业人员数_电力、热力、燃气及水生产和供应业 城镇非私营单位就业人员数_建筑业 城镇非私营单位就业人员数_批发和零售业 城镇非私营单位就业人员数_交通运输、仓储和邮政业 城镇非私营单位就业人员数_住宿和餐饮业 城镇非私营单位就业人员数_信息传输、软件和信息技术服务业 城镇非私营单位就业人员数_金融业 城镇非私营单位就业人员数_房地产业 城镇非私营单位就业人员数_租赁和商务服务业 城镇非私营单位就业人员数_科学研究和技术服务业 城镇非私营单位就业人员数_水利、环境和公共设施管理业 城镇非私营单位就业人员数_居民服务、修理和其他服务业 城镇非私营单位就业人员数_教育 城镇非私营单位就业人员数_卫生和社会工作 城镇非私营单位就业人员数_文化、体育和娱乐业 城镇非私营单位就业人员数_公共管理、社会保障和社会组织 城镇非私营单位在岗职工平均人数 城镇就业人员数_私营企业和个体 城镇非私营单位在岗职工工资总额 城镇非私营单位在岗职工平均工资 城镇登记失业人员数 建成区面积 建设用地面积 建设用地面积_居住用地 液化石油气供气总量 液化石油气供气总量_居民家庭 人工煤气、天然气供气总量 人工煤气、天然气供气总量_居民家庭 液化石油气用气人口 人工煤气、天然气用气人口 城市公共汽电车运营车辆数 城市出租汽车运营车辆数 城市公共汽电车客运总量 道路面积 排水管道长度 建成区绿化覆盖面积 建成区绿化覆盖率 绿地面积 公园绿地面积 维护建设资金支出 土地面积 生活用水供水量 供水总量 全社会用电量 城乡居民生活用电量 工业生产用电量 房地产开发投资 房地产开发投资_住宅 限额以上批发和零售业法人单位数 限额以上批发和零售业商品销售总额 普通中学学校数 中等职业教育学校数 普通小学学校数 普通高等学校专任教师数 普通中学专任教师数 中等职业教育专任教师数 普通小学专任教师数 普通高等学校在校生数 普通中学在校生数 中等职业教育在校生数 普通小学在校生数 电视节目综合人口覆盖率 公共图书馆总藏量_图书 医疗卫生机构数_医院和卫生院 卫生人员数_执业(助理)医师 医疗卫生机构床位数_医院和卫生院 城镇职工基本养老保险参保人数 职工基本医疗保险参保人数 失业保险参保人数

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值