📄 chp5.htm
字号:
<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"'>
for(y=0;y<bi.biHeight;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"'>
lpPtr=(char *)lpImgData+(BufSize-LineBytes-y*LineBytes);<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"'>
lpTempPtr=(char *)lpTempImgData+(BufSize-LineBytes-y*LineBytes);<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"'>
for(x=0;x<bi.biWidth;x++){<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"'>
Blue=(unsigned char )(*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"'>
Green=(unsigned char )(*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"'>
Red=(unsigned char )(*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"'>
//</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"'>
*(lpTempPtr++)=(unsigned char)(255-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"'>
*(lpTempPtr++)=(unsigned char)(255-Green);<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"'>
*(lpTempPtr++)=(unsigned char)(255-Red);<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"'>
}<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"'>if(hBitmap!=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"'>
DeleteObject(hBitmap);<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"'>hBitmap=CreateDIBitmap(hDc,(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"'>(LONG)CBM_INIT,<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)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"'>sizeof(BITMAPINFOHEADER)+<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"'>
NumColors*sizeof(RGBQUAD),<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"'>
(LPBITMAPINFO)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"'>DIB_RGB_COLORS);<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(hPalette &&
hPrevPalette){<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"'>
SelectPalette(hDc,hPrevPalette,FALSE);<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"'>
RealizePalette(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"'> }<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"'>hf=_lcreat("c:\\invert.bmp",0);<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"'>
_lwrite(hf,(LPSTR)&bf,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"'>
_lwrite(hf,(LPSTR)lpTempImgData,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"'> _lclose(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"'> //</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"'> ReleaseDC(hWnd,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"'>
LocalUnlock(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"'> LocalFree(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"'> GlobalUnlock(hImgData);<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"'> return TRUE;<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>
<h2 style='text-align:justify;text-justify:inter-ideograph'><span
style='font-family:"Times New Roman"'>5.2 </span><span lang=ZH-CN
style='mso-ascii-font-family:"Times New Roman";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"'>2</span><span
lang=ZH-CN style='font-size:10.5pt'>章中提到了</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>YUV</span><span lang=ZH-CN style='font-size:
10.5pt'>的颜色表示方法,在这种表示方法中,</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>Y</span><span
lang=ZH-CN style='font-size:10.5pt'>分量的物理含义就是亮度,它含了灰度图</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>(grayscale)</span><span
lang=ZH-CN style='font-size:10.5pt'>的所有信息,只用</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>Y</span><span lang=ZH-CN style='font-size:10.5pt'>分量就完全能够表示出一幅灰度图来。</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>YUV</span><span
lang=ZH-CN style='font-size:10.5pt'>和</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>RGB</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 align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;
line-height:18.0pt'><sub><span style='font-size:10.5pt;font-family:"Times New Roman"'><!--[if gte vml 1]><v:shape
id="_x0000_i1027" type="#_x0000_t75" alt="" style='width:264pt;height:57.75pt'>
<v:imagedata src="./chp5.files/image003.gif" o:href="http://www-scf.usc.edu/~flv/ipbook/chap05.files/image006.gif"/>
</v:shape><![endif]--><![if !vml]><img width=352 height=77
src="./chp5.files/image003.gif" v:shapes="_x0000_i1027"><![endif]></span></sub><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"'>Y</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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -