1 / 18

第 4 章 图形( Graphic )

第 4 章 图形( Graphic ). 4.1 DC 和 GDI 4.2 CDC 类 4.3 CPen 类 4.4 CBrush 类 4.5 绘图模式 4.6 文本和 CFont 类 4.7 CDC 的其他派生类. 应用程序. DC. 设备驱动程序. 物理图形设备. 4.1 DC 和 GDI. Windows 是依靠 图形设备接口 ( GDI )和 设备描述环境 ( DC )对图形进行支持的。. 1. 设备描述环境. DC (Device Context). 虚拟图形设备(隐藏了底层的千差万别). 画板 Canvas.

tuan
Télécharger la présentation

第 4 章 图形( Graphic )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第4章 图形(Graphic) 4.1 DC和GDI 4.2 CDC类 4.3 CPen类 4.4 CBrush类 4.5 绘图模式 4.6 文本和CFont类 4.7 CDC的其他派生类

  2. 应用程序 DC 设备驱动程序 物理图形设备 4.1 DC和GDI Windows是依靠图形设备接口(GDI)和设备描述环境(DC)对图形进行支持的。 1. 设备描述环境 DC (Device Context) 虚拟图形设备(隐藏了底层的千差万别) 画板 Canvas 数据结构:图形设备描述表,虚拟图形设备的属性。该表也叫做图形设备描述环境,简称DC.

  3. 4.1 DC和GDI 2. Windows的GDI • GDI (Graphical Device Interface, 图形设备接口) • Windows把用于改变DC属性的操作做成函数,这些函数的集合叫做GDI。 • DC种类多,如显示器、文件、打印机等。绘图前必须先确定DC。 • GDI提供完整的绘图工具。如笔、刷、字体等。这些工具不能删除,只能在同类工具之间进行替换。

  4. CDC class DC GDI 4.2 CDC类 将DC和GDI的功能进行封装,形成CDC类。 CObject CDC CPaintDC CClientDC CWindowDC CMetaFileDC 代表窗口用户区,在OnDraw()函数中来处理WM_PAINT消息 在整个窗口内(不只是用户区)绘图的DC 图元文件的DC,在创建可以回放的图像时使用 代表窗口客户区,但应用在WM_PAINT消息之外的消息处理函数中

  5. 4.2 CDC类 表4-2 CDC类中一些常用的成员函数

  6. 4.2 CDC类 关于CView::OnDraw函数 OnDraw(CDC * pDC); pDC实际上是CPaintDC类型的指针 调用 WM_PAINT 用户也可以强制产生WM_PAINT消息 如InvalidateRect()等 产生 系统创建窗口以及窗口需要刷新时 P82: 例4-1

  7. CObject CGdiObject CPen 4.3 CPen类 画笔(CPen类):用于绘制线条。 默认画笔:实线(style)、1pixel(width)、Black(color) • 属性: • style • width • color 画笔的使用方法: • COLORREF • The COLORREF value is a 32-bit value used to specify an RGB color. E.g. 0x00rrggbb • COLORREF RGB(BYTE bRed, BYTE bGreen, BYTE bBlue); 1. 新建画笔对象,并确定其属性 CPen(int style, int width, COLORREF color) CPen newPen(PS_SOLID, 2, RGB(255,0,0); 2. 替换原画笔,使用CDC::SelectObject() CPen * SelectObject(CPen * pPen); CPen * pOldPen = pDC->SelectObject(&newPen); 3. 恢复原画笔,仍使用CDC::SelectObject() pDC->SelectObject(pOldPen);

  8. 4.3 CPen类

  9. CObject CGdiObject CBrush 4.4 CBrush类 画刷(CBrush)类:对封闭图形内部用颜色或图案进行填充。 • 属性: • STYLE • COLORREF 构造函数原型: CBrush(COLORREF color); CBrush(int style, COLORREF color);

  10. 4.4 CBrush类 P85:例4-4

  11. 4.5 绘图模式 前景色的混合模式 绘图的最终效果可通过设定不同的绘图模式来修饰。 设置途径:CDC::SetROP2(int nDrawMode);, The SetROP2 function sets the current foreground mix mode. GDI uses the foreground mix mode to combine pens and interiors of filled objects with the colors already on the screen. The foreground mix mode defines how colors from the brush or pen and the colors in the existing image are to be combined.

  12. 4.5 绘图模式 例 4-A

  13. 4.6 文本和CFont类 自学

  14. WM_PAINT CPaintDC::OnDraw 用户区 CClientDC WM_PAINT 4.7 CDC的其他派生类 窗口用户区设备描述环境CClientDC类 CClientDC比CPaintDC更加灵活

  15. 单击鼠标时,绘制完整的菱形 窗口被遮盖后,复原 4.7 CDC的其他派生类 窗口用户区设备描述环境CClientDC类 用户区没有重新绘制,为什么?

  16. 4.7 CDC的其他派生类 图元文件设备描述环境CMetaFileDC类 • 图元文件(MetaFile):图形事先绘制好并存放在一个文件,并存储在内存中,需要时直接打开它,这种图形文件叫做图元文件。 • CMetaFileDC类 • 一般在CView::OnCreate()创建 • 在需要绘制时,CDC::playMetaFile() • 使用完毕需要销毁,DeleteMetaFile() P94: 例4-10 图元文件句柄

  17. 4.7 CDC的其他派生类 图元文件设备描述环境CMetaFileDC类 已生成图元文件

  18. 4.7 CDC的其他派生类 图元文件设备描述环境CMetaFileDC类 使用图元文件 别忘了销毁 CClientDC( CWnd* pWnd ); Use this constructor to construct a CClientDC object that accesses the client area of the CWnd pointed to by pWnd.

More Related