1.CPtrArray指针数组

2.CPtrArray返回void指针,需要做类型转换

3.View类中的OnPaint调用OnPrepareDC和OnDraw,如果覆盖OnPaint,就不会调用OnDraw(除非显式调用)

4.坐标空间

Coordinate Spaces and Transformations

Win32®-based applications use coordinate spaces and transformations to scale, rotate, translate, shear, and reflect graphics output. A coordinate space is a planar space that locates two-dimensional objects by using two reference axes that are perpendicular to each other. There are four coordinate spaces: world, page, device, and physical device (client area, desktop, or page of printer paper).

A transformation is an algorithm that alters ("transforms") the size, orientation, and shape of objects. Transformations also transfer a graphics object from one coordinate space to another. Ultimately, the object appears on the physical device, which is usually a screen or printer.

About Coordinate Spaces and Transformations

Coordinate spaces and transformations are used by the following types of applications:

Desktop publishing applications (to "zoom" parts of a page or to display adjacent pages in a window).

Computer-aided design (CAD) applications (to rotate objects, scale drawings, or create perspective views).

Spreadsheet applications (to move and size graphs).

The following illustrations show successive views of an object created in a drawing application. The first illustration shows the object as it appears in the original drawing; the succeeding five illustrations show the effects of applying various transformations.

Using Coordinate Spaces and Transformations

This section contains an example that demonstrates the following tasks:

Drawing graphics with predefined units.

Centering graphics in the application's client area.

Scaling graphics output to half its original size.

Translating graphics output 3/4 of an inch to the right.

Rotating graphics 30 degrees.

Shearing graphics output along the x-axis.

Reflecting graphics output about an imaginary horizontal axis drawn through its midpoint.

The following example was used to create the illustrations that appear earlier in this overview.

void TransformAndDraw(int iTransform, HWND hWnd)

{

HDC hDC;

XFORM xForm;

RECT rect;

// Retrieve a DC handle for the application's window.

hDC = GetDC(hWnd);

// Set the mapping mode to LOENGLISH. This moves the

// client area origin from the upper left corner of the

// window to the lower left corner (this also reorients

// the y-axis so that drawing operations occur in a true

// Cartesian space). It guarantees portability so that

// the object drawn retains its dimensions on any display.

SetGraphicsMode(hDC, GM_ADVANCED);

SetMapMode(hDC, MM_LOENGLISH);

// Set the appropriate world transformation (based on the

// user's menu selection).

switch (iTransform)

{

case SCALE:        // Scale to 1/2 of the original size.

xForm.eM11 = (FLOAT) 0.5;

xForm.eM12 = (FLOAT) 0.0;

xForm.eM21 = (FLOAT) 0.0;

xForm.eM22 = (FLOAT) 0.5;

xForm.eDx  = (FLOAT) 0.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

case TRANSLATE:   // Translate right by 3/4 inch.

xForm.eM11 = (FLOAT) 1.0;

xForm.eM12 = (FLOAT) 0.0;

xForm.eM21 = (FLOAT) 0.0;

xForm.eM22 = (FLOAT) 1.0;

xForm.eDx  = (FLOAT) 75.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

case ROTATE:      // Rotate 30 degrees counterclockwise.

xForm.eM11 = (FLOAT) 0.8660;

xForm.eM12 = (FLOAT) 0.5000;

xForm.eM21 = (FLOAT) -0.5000;

xForm.eM22 = (FLOAT) 0.8660;

xForm.eDx  = (FLOAT) 0.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

case SHEAR:       // Shear along the x-axis with a

// proportionality constant of 1.0.

xForm.eM11 = (FLOAT) 1.0;

xForm.eM12 = (FLOAT) 1.0;

xForm.eM21 = (FLOAT) 0.0;

xForm.eM22 = (FLOAT) 1.0;

xForm.eDx  = (FLOAT) 0.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

case REFLECT:     // Reflect about a horizontal axis.

xForm.eM11 = (FLOAT) 1.0;

xForm.eM12 = (FLOAT) 0.0;

xForm.eM21 = (FLOAT) 0.0;

xForm.eM22 = (FLOAT) -1.0;

xForm.eDx  = (FLOAT) 0.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

case NORMAL:      // Set the unity transformation.

xForm.eM11 = (FLOAT) 1.0;

xForm.eM12 = (FLOAT) 0.0;

xForm.eM21 = (FLOAT) 0.0;

xForm.eM22 = (FLOAT) 1.0;

xForm.eDx  = (FLOAT) 0.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

}

// Find the midpoint of the client area.

GetClientRect(hWnd, (LPRECT) &rect);

DPtoLP(hDC, (LPPOINT) &rect, 2);

// Select a hollow brush.

SelectObject(hDC, GetStockObject(HOLLOW_BRUSH));

// Draw the exterior circle.

Ellipse(hDC, (rect.right / 2 - 100), (rect.bottom / 2 + 100),

(rect.right / 2 + 100), (rect.bottom / 2 - 100));

// Draw the interior circle.

Ellipse(hDC, (rect.right / 2 -94), (rect.bottom / 2 + 94),

(rect.right / 2 + 94), (rect.bottom / 2 - 94));

// Draw the key.

Rectangle(hDC, (rect.right / 2 - 13), (rect.bottom / 2 + 113),

(rect.right / 2 + 13), (rect.bottom / 2 + 50));

Rectangle(hDC, (rect.right / 2 - 13), (rect.bottom / 2 + 96),

(rect.right / 2 + 13), (rect.bottom / 2 + 50));

// Draw the horizontal lines.

MoveToEx(hDC, (rect.right/2 - 150), (rect.bottom / 2 + 0), NULL);

LineTo(hDC, (rect.right / 2 - 16), (rect.bottom / 2 + 0));

MoveToEx(hDC, (rect.right / 2 - 13), (rect.bottom / 2 + 0), NULL);

LineTo(hDC, (rect.right / 2 + 13), (rect.bottom / 2 + 0));

MoveToEx(hDC, (rect.right / 2 + 16), (rect.bottom / 2 + 0), NULL);

LineTo(hDC, (rect.right / 2 + 150), (rect.bottom / 2 + 0));

// Draw the vertical lines.

MoveToEx(hDC, (rect.right/2 + 0), (rect.bottom / 2 - 150), NULL);

LineTo(hDC, (rect.right / 2 + 0), (rect.bottom / 2 - 16));

MoveToEx(hDC, (rect.right / 2 + 0), (rect.bottom / 2 - 13), NULL);

LineTo(hDC, (rect.right / 2 + 0), (rect.bottom / 2 + 13));

MoveToEx(hDC, (rect.right / 2 + 0), (rect.bottom / 2 + 16), NULL);

LineTo(hDC, (rect.right / 2 + 0), (rect.bottom / 2 + 150));

ReleaseDC(hWnd, hDC);

}

5.SetScrollSizes设置滚动条大小

第一个参数是映射模式:

6.SetMapMode可以改变映射模式

7.逻辑坐标和设备坐标转换

8. OnInitialUpdate是窗口创建完成之后第一个被调用的函数(在OnDraw之前),可以在这里设置滚动条大小

9.视口和窗口原点的改变

10.DPtoLP将设备点转换为逻辑点

11.LPtoDP将逻辑点转换为设备点

12.利用CMetaFileDC类保存与重现画布

13.CMetaFileDC::Create会创建一个源文件,如果参数为NULL,会创建一个内存文件

14.CMetaFileDC::Close方法会关闭DC,返回HMETAFILE(源文件句柄)对象

15.PlayMetaFile重现画布

16.DeleteMetaFile删除源文件

17.CopyMetaFile将源文件保存至文件

18.GetMetaFile(GetEnhMetaFile)从文件或取Meta File

19.CreateCompatibleBitmap 初始化一个位图与指定DC兼容

20.兼容DC也是内存DC,在窗口中不可见

21.

22.总结:

保存图像的三种方法:

*1.保存绘图操作步骤

*2.使用CMetaFileDC重现画布

*3.使用兼容位图,复制位图到当前DC

 用菊子曰博客,就是爽!

孙鑫MFC学习笔记11:保存图像的更多相关文章

  1. 孙鑫MFC学习笔记13:文档

    1.CArchive类保存内存数据 2.CAchive类重载了>>与<<操作符,类似C++文件流 3.在OnNewDocument中通过SetTitle设置标题 4.字符串资源 ...

  2. 孙鑫MFC学习笔记12:文件读写

    1.指向常量的指针 2.指针常量 3.C语言对文件操作是在缓冲区,在缓冲区满或文件关闭时写入文件 读取相同 4.fflush刷新缓冲区,使缓冲区数据写入文件 5.fseek改变文件指针偏移量 6.st ...

  3. 孙鑫MFC学习笔记4:MFC画图

    1.画线方法 *1.捕获鼠标按下和弹起消息,获取两个点 *2.消息响应,画线 2.在CMainFrame类中的鼠标左键事件得不到响应的原因是CNameView覆盖了CMainFrame 3.注释宏 4 ...

  4. 孙鑫MFC学习笔记3:MFC程序运行过程

    1.MFC中WinMain函数的位置在APPMODUL.cpp APPMODUL.cpp中是_tWinMain,其实_tWinMain是一个宏#define _tWinMain WinMain 2.全 ...

  5. 孙鑫MFC学习笔记17:进程间通信

    17 1.进程间通信4种方式 2.OpenClipboard打开剪贴板 3.EmptyClipboard清空剪贴板,并把所有权分配给打开剪贴板的窗口 4.SetClipboardData设置剪贴板数据 ...

  6. 孙鑫MFC学习笔记16:异步套接字

    16 1.事件对象 2.CreateEvent创建事件对象 3.SetEvent设置事件对象为通知状态 4.ResetEvent设置事件对象为非通知状态 5.InitializeCriticalSec ...

  7. 孙鑫MFC学习笔记14:网络编程

    1.OSI 2.TCP/IP与OSI对应关系 3.Socket 4.客户机/服务器模式 5.Windows Sockets 6.套接字类型 7.面向连接的socket编程 8.面向无连接的socket ...

  8. 孙鑫MFC学习笔记10:画图/贴图

    1.SetPixel在指定点设置像素 2.虚线.点线宽度必须为1 3.CColorDialog创建颜色对话框 4.需要设置CC_RGBINIT标志才能设置颜色对话框的默认颜色 5.CC_FULLOPE ...

  9. 孙鑫MFC学习笔记9:状态栏与工具栏编程

    1.在窗口创建之前就应该修改窗口的样式 2.单文档应用程序会把文档名作为应用程序标题,应该去掉FWS_ADDTOTITLE属性,然后修改lpszName为标题 3.在窗口创建完成后,可以通过SetWi ...

随机推荐

  1. IOS Animation-贝塞尔曲线与Layer简单篇(一)

    IOS Animation-贝塞尔曲线与Layer简单篇 swift篇 1.介绍 贝塞尔曲线: 贝塞尔曲线是计算机图形图像造型的基本工具,是图形造型运用得最多的基本线条之一.它通过控制曲线上的四个点( ...

  2. 分割超大Redis数据库例子

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/124.html?1455853509 薄荷 App 上的伙伴功能大量使用了 ...

  3. WebApi系列~安全校验中的防篡改和防复用

    回到目录 web api越来越火,因为它的跨平台,因为它的简单,因为它支持xml,json等流行的数据协议,我们在开发基于面向服务的API时,有个问题一直在困扰着我们,那就是数据的安全,请求的安全,一 ...

  4. Atitit  基于meta的orm,提升加速数据库相关应用的开发

    Atitit  基于meta的orm,提升加速数据库相关应用的开发 1.1. Overview概论1 1.2. Function & Feature功能特性1 1.2.1. meta api2 ...

  5. tabs左右滚动

    $(function () { //IdivLeft小于0,说明左边还有菜单,菜单总数大于8 //IdivLeft等于0,说明菜单总数小于8 //IdivLeft大于0,说明右边还有菜单,菜单总数大于 ...

  6. SQL*Loader之CASE11

    CASE11 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase11.sql set termout off rem host write sys$output &q ...

  7. HTML5移动Web开发(二)——配置移动开发环境以及简单示例

    一.准备 1.配置本地网络服务.对于Windows.Mac和Linux,最容易的方法是使用免费的XAMPP软件:http://www.apachefriends.org/en/index.html X ...

  8. 牛顿法与拟牛顿法学习笔记(三)DFP 算法

    机器学习算法中经常碰到非线性优化问题,如 Sparse Filtering 算法,其主要工作在于求解一个非线性极小化问题.在具体实现中,大多调用的是成熟的软件包做支撑,其中最常用的一个算法是 L-BF ...

  9. C语言打印记事本内搜索字符串所在行信息

    本程序采用C语言编写,使用方法: 1.双击“甲骨文字符串查询作品.exe”运行程序; 2.运行前请确保此可执行程序目录下有1.txt文件. 3.根据提示输入一个字符串,程序将显示存在所搜索字符串的所有 ...

  10. java设计模式(六)--观察者模式

    转载:设计模式(中文-文字版) 目录: 简单目标任务实现 观察者模式介绍 观察者模式代码实现 观察者模式是JDK中使用最多的模式之一,非常有用.我们也会一并介绍一对多关系,以及松耦合(对,没错,我们说 ...