图像处理之-位图
- MD DoCumEnT: 3/16/2016 5:59:48 PM by Jimbowhy
自从发现MarkdownPad以后,就沉迷于写作,从未有过这样的浸淫,完全没有了生物钟的同期,基本上只要醒着,手眼就离不了屏幕,离不了键盘,一直敲着几近光滑的按键,那种感觉就是满足,如果要用个词来形容,我觉得 F**KING WRITING! F**KING MY LIFE! 是恰当的。生命有终结的一天,而文字却不会。 - by Jimbowhy 3/20/2016 4:32:04 PM
虽然本文的标题只说是位图图像处理,其实内容远比标题丰富,原本计划是只涉及位图的文件结构分析和代码实现。但一头扎下去,就搞大了,从GDI到CONSOLE,从VGA到API绘图,我觉得比较有趣的点基本都染指了。因为图像处理本来就是很深又广的领域,程序开发过程中不免也要和图形打交道,而且BMP对于当前使用的Window操作系统是如此的重要,以致为它写一本书的内容都是可以收集到的。
目录
背景知识
GDI绘图API构架
图像透明处理
控制台下绘图
动画与实现
制作单独执行文件
内容国际化
关于代码页,在99OCT版的MSDN上有一本书《Developing International Software for Windows 95 and Windows NT》,里面有大量关于国际化的内容,这本书是单独的一个 DEVINTL.CHM 文件,将近50MB,可谓内容丰富啊。本文就是为了上传它特意先占位发布的,下载地址请转到资源中心!
本书Amazon有售只要 $1.97 刀,宝啊!关于作者 Kano 女士:
Nadine Kano joined Microsoft Corporation in 1989 after graduating from Princeton University with a degree in computer science engineering. She worked for three years as the international developer responsible for localized editions of Microsoft Word for Windows. In 1993 she joined the Developer Relations Group as a member of the Globalization Team. Nadine regularly publishes articles in the Microsoft Developer Network News on software internationalization and travels around the world giving lectures on internationalization techniques. She lives in Palo Alto, California.
MSDN补充
替换MSDN930.COL路径就可以安装 MSDN 1999 OCT 版,Visual C++ 6 可以直接F1访问。
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\HTML Help Collections\Developer Collections\0x0804]
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\HTML Help Collections\Developer Collections\0x0804\0x0358e0f00]
"Filename"="C:\\Program Files (x86)\\Microsoft Visual Studio\\MSDN98\\98VS\\2052\\msdnvs98.col"
@="MSDN Library - Visual Studio 6.0"
"Full"=dword:00000001
Visual Studio 6.0 补充
编译代码使用的工具是 TDM-GCC 4.71,由于它包含的头文件内容和 VC6 不同,而且是 include 上的功能也有所差别。所以代码改用 CL.exe 编译时可能会有问题,比如我尝试过的几个例子。GCC 只要引用 cstring 和 iostream 就可以使用 cout 的输出重载操作符了,因为通过 g++ 编译时它会自动添加 C++ 的标准类库:
#include <iostream>
#include <cstring>
但是在VC6下就要包含C++的字符串头文件:
#include <string>
否则,就会出离奇的编译错误,因为编译会当移位运算符来处理:
mouse.cpp(241) : error C2679: binary '<<' : no operator defined which takes a ri
ght-hand operand of type 'class std::basic_string<char,struct std::char_traits<c
har>,class std::allocator<char> >' (or there is no acceptable conversion)
另外提醒一下,如果不注意C语言和C++语言的头文件引用语法差别也会导致编译不能通过。以标准库文件为例,C语言的头文件后面有 .h 扩展名,而C++的没有,所以下面这条引用会被当成C语言来处理:
#include <iostream.h>
如果要想在C++中使用C语言的库文件,最佳的引用方法是去掉后缀名,加前缀c,如C语言的数学库文件:
#include <cmath>
这样看代码就可以知道这是在用C++写的程序,如果要用C语言写则可以后缀 .h 来引用库文件。但是尽量不要混用,尽管 C++ 兼容 C。
直接在代码字符中使用中文多字节符号也会出现常量断行的错误,只要中文编码中出现 0xE2 0x80 0xA2 这些值,就会有这个错误提示,比如说中文的句号它在UTF8编码时就会包含一个 0x80,还有中的一字也是一样。这个只能算是VC6的八啊哥了:
error C2001: newline in constant
这个问题即使引用 TCHAR.H 的 _T、_TCHAR 也不能解决。如果一定要在代码中使用中文,可以考改变代码文件的编译方案,列如 UTF8,GBK,UNICODE 互换试试,也许就可以通过编译,但是字符串就要求相应的编译支持,否则程序输出就会乱码。更好的解决方法是使用资源文件,通过 rc.exe 命令来编译:
RC.EXE /l 0x804 /c 936 /d_DEBUG /fo.\GENERIC.RES /r GENERIC.RC
示例图表:
+----------------------------------------+----------------------------------------+
| Client Side | Server Side |
| +--------+--------+ |
| | Event | |
| +--------+--------+ |
| +------------+-----------+ |
| | Memory Windows | |
| +------------+-----------+ |
| GDI via hBitmap +--------------+--------------+ |
| -------------------->| | |
| | DIB Section +------+ |
| -------------------->| | | BitBlt |
| Directly via pBits +--------------+--------------+ | |
| | | |
+----------------------------------------+---------------------+------------------+
| Kernel Side | |
+--------------------------------------------------------------+------------------+
| V |
| Hardware Video Memory |
| |
+---------------------------------------------------------------------------------+
y axis y axis
A A
| ******** | __cg********
| ******** | __cg*****^^
| ******** | __cg*****^^
| ******** | *****^^
+--------------------------------> x axis +--------------------------------> x axis
示例图片:
占个位置,丰富内容正在完成中…
资源参考
- MSDN - Platform SDK: Windows GDI BITMAPINFO
- WiKI - BMP file format
- Microsoft Windows Bitmap File Format Summary
- use GDI to draw on the console window
- 256-Color VGA Programming in C
- DOS development tool - DJGPP 2.0
- Graphics Programming Using VGA Mode 13h
- Top-Down vs. Bottom-Up DIBs
- Guide to Image Composition with MsImg32.dll - Paul M. Watt
- 透明位图的显示 - 王骏 (光栅操作太过复杂,没能说明白SetBkColor的作用)
- Platform SDK Redistributable: GDI+
- Windows® Server 2003 SP1 Platform SDK ISO
- Using mc.exe message resources and the NT event log - Daniel Lohmann
- Get World-Class Noise and Total Joy from Your Games - Dave Edson
- 《Developing International Software for Windows 95 and Windows NT》 DEVINTL.CHM