📄 chp5.htm
字号:
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" alt="" style='width:198pt;
height:158.25pt'>
<v:imagedata src="./chp5.files/image001.jpg" o:href="http://www-scf.usc.edu/~flv/ipbook/chap05.files/image002.jpg"/>
</v:shape><![endif]--><![if !vml]><img width=264 height=211
src="./chp5.files/image001.jpg" v:shapes="_x0000_i1025"><![endif]><o:p></o:p></span></p>
<p align=center style='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"'>5.1 </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>
</td>
<td width=276 valign=top style='width:207.0pt;padding:0cm 0cm 0cm 0cm'>
<p style='text-align:justify;text-justify:inter-ideograph;line-height:18.0pt'><span
style='font-size:10.5pt;font-family:"Times New Roman"'><!--[if gte vml 1]><v:shape
id="_x0000_i1026" type="#_x0000_t75" alt="" style='width:199.5pt;height:159.75pt'>
<v:imagedata src="./chp5.files/image002.jpg" o:href="http://www-scf.usc.edu/~flv/ipbook/chap05.files/image004.jpg"/>
</v:shape><![endif]--><![if !vml]><img width=266 height=213
src="./chp5.files/image002.jpg" v:shapes="_x0000_i1026"><![endif]><o:p></o:p></span></p>
<p align=center style='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"'>5.2 </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"'>5.1</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>
</td>
</tr>
</table>
</div>
<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"'>5.1</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><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"'>256</span><span 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"'>255</span><span
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"'>(</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 lang=ZH-CN style='font-size:10.5pt'>先看看真彩图。我们知道真彩图不带调色板,每个象素用</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>3</span><span
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"'>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"'><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'><span 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 lang=ZH-CN 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 lang=ZH-CN style='font-size:10.5pt'>这里,我想澄清一个概念。过去我们讲二值图时,一直都说成黑白图。二值位图一定是黑白的吗?答案是不一定。我们安装</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>Windows95</span><span
lang=ZH-CN style='font-size:10.5pt'>时看到的那幅</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>setup.bmp</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><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"'>BOOL Invert(HWND hWnd)<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"'>{<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
OffBits,BufSize;<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"'>LPBITMAPINFOHEADER lpImgData;<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"'>
LPSTR
lpPtr;<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"'>
HLOCAL
hTempImgData;<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"'>
LPBITMAPINFOHEADER lpTempImgData;<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"'>
LPSTR
lpTempPtr;<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"'>
HDC
hDc;<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"'>
HFILE
hf;<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
x,y;<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"'> LOGPALETTE
*pPal;<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"'>
HPALETTE
hPrevPalette=NULL; <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"'>
HLOCAL
hPal;<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
i;<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"'> unsigned
char
Red,Green,Blue;<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"'>
OffBits=bf.bfOffBits-sizeof(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 style='font-size:10.5pt;font-family:
"Times New Roman"'>
BufSize=OffBits+bi.biHeight*LineBytes; //</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"'>
if((hTempImgData=LocalAlloc(LHND,BufSize))==NULL)<o:p></o:p></span></p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -