GDI+学习及代码总结之------画线、区域填充、写字.docx

上传人:A*** 文档编号:142724895 上传时间:2020-08-22 格式:DOCX 页数:10 大小:157.41KB
返回 下载 相关 举报
GDI+学习及代码总结之------画线、区域填充、写字.docx_第1页
第1页 / 共10页
GDI+学习及代码总结之------画线、区域填充、写字.docx_第2页
第2页 / 共10页
GDI+学习及代码总结之------画线、区域填充、写字.docx_第3页
第3页 / 共10页
GDI+学习及代码总结之------画线、区域填充、写字.docx_第4页
第4页 / 共10页
GDI+学习及代码总结之------画线、区域填充、写字.docx_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《GDI+学习及代码总结之------画线、区域填充、写字.docx》由会员分享,可在线阅读,更多相关《GDI+学习及代码总结之------画线、区域填充、写字.docx(10页珍藏版)》请在金锄头文库上搜索。

1、GDI+学习及代码总结之-画线、区域填充、写字精通GDI编程里的代码,在学习过程中对它加以总结,以防以后用到,所有代码都是在MFC 单文档中实现的,写在View:OnDraw(CDC */*pDC*/)中画线/边框(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); P

2、ointF point1(10.0f, 10.0f); PointF point2(10.0f, 100.0f); PointF point3(200.0f, 50.0f); PointF point4(250.0f, 80.0f); PointF points4 = point1, point2, point3, point4; PointF* pPoints = points; graphics.DrawLines(&blackPen, pPoints, 4);讲解:points数组中的每个点都是连接线上的转折点,DrawLines会把它们按照顺序一个个连接起来3、画矩形-DrawRect

3、angle,只画边框,不画背景色 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.

4、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 curvePoint

5、s4 = 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.FillEll

6、ipse(&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);/开始点

7、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 curvePoints7 = point1, point2, point3, point4, point5, point6, point7; PointF* pcurvePoints = curvePoints

8、; /画闭合曲线 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

9、(&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,既然能画闭合的

10、曲线,肯定也有闭合的直线,当然闭合的直线也就是所谓的多边形 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 points5 = point1, point2, point3, point4

11、, 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);

12、 /画出边框,做为参考 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, st

13、artAngle, sweepAngle);先出效果图:这里要对它两上名词讲解一下,什么叫startAngle(开始度数),什么叫sweepAngle(范围度数也能叫扫过度数,我译的,嘿嘿)看下MSDN里对DrawPie函数的讲解就会懂了,里面有这个图,给大家看一下填充区域(SolidBrush)1、填充闭合区域-FillClosedCurve,边框对应:DrawClosedCurve 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 points4 = point1, point2, point3, point4; /填充闭合区域 graphics.FillClosedCurve(&blackBrush, points, 4); /为闭合区域画边框 Pe

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号