📄 chp1.htm
字号:
lang=ZH-CN style='font-size:10.5pt'>个字节的大调色板。所以真彩色图直接用</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>R</span><span
lang=ZH-CN style='font-size:10.5pt'>、</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>G</span><span lang=ZH-CN style='font-size:10.5pt'>、</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>B</span><span
lang=ZH-CN style='font-size:10.5pt'>三个分量表示,它又叫做</span><span style='font-size:
10.5pt;font-family:"Times New Roman"'>24</span><span lang=ZH-CN
style='font-size:10.5pt'>位色图。</span><span style='font-size:10.5pt;font-family:
"Times New Roman"'><o:p></o:p></span></p>
<h2 style='text-align:justify;text-justify:inter-ideograph'><span
style='font-family:"Times New Roman"'>1.2 bmp</span><span lang=ZH-CN
style='font-family:黑体;mso-hansi-font-family:"Times New Roman"'>文件格式</span><span
style='font-family:"Times New Roman"'><o:p></o:p></span></h2>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>介绍完位图和调色板的概念,下面就让我们来看一看</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>Windows</span><span
lang=ZH-CN style='font-size:10.5pt'>的位图文件</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>(.bmp</span><span lang=ZH-CN style='font-size:
10.5pt'>文件</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>)</span><span
lang=ZH-CN style='font-size:10.5pt'>的格式是什么样子的。</span><span style='font-size:
10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>bmp</span><span lang=ZH-CN style='font-size:10.5pt'>文件大体上分成四个部分,如图</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>1.3</span><span
lang=ZH-CN style='font-size:10.5pt'>所示。</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'><o:p></o:p></span></p>
<div align=center>
<table border=1 cellspacing=0 cellpadding=0 width="80%" style='width:80.0%;
mso-cellspacing:0cm;mso-padding-alt:0cm 0cm 0cm 0cm'>
<tr>
<td width=455 valign=top style='width:341.25pt;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center;line-height:18.0pt'><span
lang=ZH-CN style='font-size:10.5pt'>位图文件头</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>BITMAPFILEHEADER<o:p></o:p></span></p>
</td>
</tr>
<tr>
<td width=455 valign=top style='width:341.25pt;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center;line-height:18.0pt'><span
lang=ZH-CN style='font-size:10.5pt'>位图信息头</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>BITMAPINFOHEADER<o:p></o:p></span></p>
</td>
</tr>
<tr>
<td width=455 valign=top style='width:341.25pt;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center;line-height:18.0pt'><span
lang=ZH-CN style='font-size:10.5pt'>调色板</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>Palette<o:p></o:p></span></p>
</td>
</tr>
<tr>
<td width=455 valign=top style='width:341.25pt;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center;line-height:18.0pt'><span
lang=ZH-CN style='font-size:10.5pt'>实际的位图数据</span><span style='font-size:
10.5pt;font-family:"Times New Roman"'>ImageDate<o:p></o:p></span></p>
</td>
</tr>
</table>
</div>
<p align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;
line-height:18.0pt'><b><span lang=ZH-CN style='font-size:10.5pt'>图</span></b><b><span
style='font-size:10.5pt;font-family:"Times New Roman"'>1.3
Windows</span></b><b><span lang=ZH-CN style='font-size:10.5pt'>位图文件结构示意图</span></b><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>第一部分为位图文件头</span><b><span
style='font-size:10.5pt;font-family:"Times New Roman"'>BITMAPFILEHEADER</span></b><span
lang=ZH-CN style='font-size:10.5pt'>,是一个结构,其定义如下:</span><span style='font-size:
10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>typedef struct tagBITMAPFILEHEADER {<o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>WORD
bfType; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>DWORD bfSize; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>WORD
bfReserved1; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>WORD
bfReserved2; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>DWORD bfOffBits; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>} BITMAPFILEHEADER; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>这个结构的长度是固定的,为</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>14</span><span
lang=ZH-CN style='font-size:10.5pt'>个字节</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>(WORD</span><span lang=ZH-CN style='font-size:
10.5pt'>为无符号</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>16</span><span
lang=ZH-CN style='font-size:10.5pt'>位整数,</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>DWORD</span><span lang=ZH-CN style='font-size:
10.5pt'>为无符号</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>32</span><span
lang=ZH-CN style='font-size:10.5pt'>位整数</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>)</span><span lang=ZH-CN style='font-size:10.5pt'>,各个域的说明如下:</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><b><span style='font-size:10.5pt;
font-family:"Times New Roman"'>bfType</span></b><span style='font-size:10.5pt;
font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>指定文件类型,必须是</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>0x424D</span><span
lang=ZH-CN style='font-size:10.5pt'>,即字符串“</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>BM</span><span lang=ZH-CN style='font-size:10.5pt'>”,也就是说所有</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>.bmp</span><span
lang=ZH-CN style='font-size:10.5pt'>文件的头两个字节都是“</span><span style='font-size:
10.5pt;font-family:"Times New Roman"'>BM</span><span lang=ZH-CN
style='font-size:10.5pt'>”。</span><span style='font-size:10.5pt;font-family:
"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><b><span style='font-size:10.5pt;
font-family:"Times New Roman"'>bfSize</span></b><span style='font-size:10.5pt;
font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>指定文件大小,包括这</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>14</span><span
lang=ZH-CN style='font-size:10.5pt'>个字节。</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><b><span style='font-size:10.5pt;
font-family:"Times New Roman"'>bfReserved1</span></b><b><span lang=ZH-CN
style='font-size:10.5pt'>,</span></b><b><span style='font-size:10.5pt;
font-family:"Times New Roman"'>bfReserved2 </span></b><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>为保留字,不用考虑</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><b><span style='font-size:10.5pt;
font-family:"Times New Roman"'>bfOffBits</span></b><span style='font-size:10.5pt;
font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>为从文件头到实际的位图数据的偏移字节数,即图</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>1.3</span><span
lang=ZH-CN style='font-size:10.5pt'>中前三个部分的长度之和。</span><span style='font-size:
10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>第二部分为位图信息头</span><b><span
style='font-size:10.5pt;font-family:"Times New Roman"'>BITMAPINFOHEADER</span></b><span
lang=ZH-CN style='font-size:10.5pt'>,也是一个结构,其定义如下:</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>typedef struct tagBITMAPINFOHEADER{<o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>DWORD biSize; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>LONG
biWidth; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>LONG
biHeight; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>WORD
biPlanes; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>WORD
biBitCount <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>DWORD biCompression; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>DWORD biSizeImage; <o:p></o:p></span></p>
<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -