📄 windows gdi和gdi+编程实例剖析_6.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0046)http://tech.bc0436.com/dev/255/2190255_5.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Windows GDI和GDI+编程实例剖析</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN>
<META content=all name=robots>
<META content="index, follow" name=googlebot>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR>
<META content="天极Yesky | 全球中文IT第一门户" name=author>
<META content="天极Yesky | 全球中文IT第一门户" name=Copyright>
<META content=硬件,软件,数码,游戏,e时代,下载,社区,评测,笔记本; name=keywords><LINK media=all
href="Windows GDI和GDI+编程实例剖析_6.files/yesky-content-cs.css" type=text/css
rel=stylesheet></HEAD>
<BODY>
<SCRIPT language=JavaScript>
function sendemail(){
OpenWindow = window.open('http://other.chinabyte.com/chinabyte/qin/sendemail-new.shtm?url=/dev/255/2190255.shtml&title=Windows GDI和GDI+编程实例剖析&channel=324','emailwin','toolbar=no,location=no,scrollbars=no,menubar=no,width=462,height=450')
}</SCRIPT>
<DIV class=width>
<DIV class=minwidth>
<DIV class=container><!--头部-->
<DIV class=hidden>yesky内容</DIV>
<SCRIPT language=JavaScript src="" type=text/JavaScript></SCRIPT>
<SPAN id=ad1 style="DISPLAY: none"></SPAN>
<DIV align=center>
<SCRIPT>document.write(navigator.userAgent.indexOf('MSIE')==-1?"<SCRIPT src='http://219.239.88.50:80/adsunion/get/;pl=pl-1-survey2005-column-051118;tp=js;sk=0;ck=0;/?'><\/SCRIPT>":"<IFRAME MARGINHEIGHT=0 MARGINWIDTH=0 FRAMEBORDER=0 BORDER=0 VSPACE=0 WIDTH=760 NORESIZE HEIGHT=90 SCROLLING=NO SRC='http://219.239.88.50:80/adsunion/get/;pl=pl-1-survey2005-column-051118;tp=if;sk=0;ck=0;/?'></IFRAME>");</SCRIPT>
</DIV>
<DIV class=clear1></DIV>
<DIV class=newbox><SPAN id=ad8></SPAN></DIV><!--导航条-->
<DIV class=newbox>
<DIV class=newbgpic>
<DIV class=left>您现在的位置: <A href="http://tech.bc0436.com/">Yesky</A>><A
href="http://tech.bc0436.com/soft"> 软件</A>><A
href="http://tech.bc0436.com/dev"> 开发者网络</A> </DIV>
<DIV class=right>
<DIV class=space1><SPAN id=ad3></SPAN></DIV></DIV></DIV></DIV>
<DIV class=clear1></DIV><!--结束-->
<DIV class=clear1></DIV><!--文章内容区-->
<DIV class=newbox>
<DIV class=newleft>
<DIV class=newleft1>
<DIV class=newsmallbox>Windows GDI和GDI+编程实例剖析 </DIV>
<DIV class=clear1></DIV>
<DIV class=newsmall1box>
<DIV class=newtitle1>作者: 宋宝华 </DIV>
<DIV class=newtitle2>出处: 天极网 </DIV>
<DIV class=newtitle3>责任编辑: <A title=向本编辑提问
href="http://comments.yesky.com/t/·½ÖÛ/6,324/2190255.shtml">方舟 </A></DIV>
<DIV class=newtitle4>[ 2005-11-11 08:18 ]</DIV></DIV>
<DIV class=clear1></DIV>
<STYLE type=text/css>A.zhy0815button_content {
BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 8px; BORDER-TOP: white 1px solid; PADDING-LEFT: 8px; FONT-SIZE: 12px; PADDING-BOTTOM: 4px; BORDER-LEFT: white 1px solid; COLOR: #000000; LINE-HEIGHT: 300%; PADDING-TOP: 4px; BORDER-BOTTOM: black 1px solid; FONT-FAMILY: "宋体"; TEXT-ALIGN: center; min-width: 75px
}
A.zhy0815button_content:link {
COLOR: #000; LINE-HEIGHT: 300%; BACKGROUND-COLOR: #d9d9d9; TEXT-DECORATION: none
}
A.zhy0815button_content:visited {
COLOR: #000000; LINE-HEIGHT: 300%; BACKGROUND-COLOR: #d9d9d9; TEXT-DECORATION: none
}
A.zhy0815button_content:hover {
BORDER-LEFT-COLOR: black; BORDER-BOTTOM-COLOR: white; COLOR: #333333; BORDER-TOP-COLOR: black; LINE-HEIGHT: 300%; BACKGROUND-COLOR: #cccccc; TEXT-DECORATION: none; BORDER-RIGHT-COLOR: white
}
A.zhy0815button_content:active {
COLOR: #000000; LINE-HEIGHT: 300%; BACKGROUND-COLOR: #d9d9d9; TEXT-DECORATION: none
}
</STYLE>
<CENTER><A class=zhy0815button_content title=编辑推荐你阅读
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#1" target=_self>推荐阅读</A> <A
class=zhy0815button_content title=本栏目的最新更新
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#2" target=_self>最新更新</A> <A
class=zhy0815button_content title=阅读此文章的读者还看了以下文章
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#3" target=_self>继续阅读</A> <A
class=zhy0815button_content title=相关主题的关键字
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#4" target=_self>相关主题</A> <A
class=zhy0815button_content title=本文编辑方舟的其他文章
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#5" target=_self>编辑新作</A> <A
class=zhy0815button_content title=本栏目最近最受欢迎的文章
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#6" target=_self>阅读排行</A> <A
class=zhy0815button_content id=comment_url_tag title=读者、编辑互动讨论区
href="http://comments.yesky.com/t/GDI/6,324/2190255.shtml">讨论本文</A><A
class=zhy0815button_content id=comment_url_art title=读者、编辑互动讨论区
href="http://comments.yesky.com/a/6,324/2190255.shtml">讨论本文</A> <A
class=zhy0815button_content title=本文相关产品和厂商
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#8" target=_self>相关产品</A>
</CENTER>
<DIV class=space2><SPAN id=ad5></SPAN></DIV><BR>
<DIV class=newmiddlebox style="OVERFLOW: hidden">
<DIV class=guanggao><SPAN id=ad4></SPAN></DIV>
<DIV class=guanggao><SPAN
id=contentAdv></SPAN></DIV> <STRONG>Alpha混合</STRONG><BR><BR> Alpha允许将两个物体混合起来显示,在3D气氛和场景渲染等方面有广泛应用。它能"雾化"图像,使得一个图像着色在另一个半透明的图像上,呈现一种朦胧美。我们知道,一个像素可用R,G,B三个维度来表示,我们可以再加上第4个即:Alpha维度(channel),表征透明程度。<BR><BR>
<TABLE borderColor=#cccccc width="90%" align=center bgColor=#e3e3e3 border=1>
<TBODY>
<TR>
<TD>void CGdiexampleDlg::OnAlphaBlend()<BR>{<BR> // TODO: Add your command
handler code here<BR> CClientDC dc(this);<BR> //创建Graphics对象<BR> Graphics
graphics(dc);<BR> //创建ColorMatrix<BR> ColorMatrix ClrMatrix
=<BR> {<BR> 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,<BR> 0.0f, 1.0f, 0.0f, 0.0f,
0.0f,<BR> 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,<BR> 0.0f, 0.0f, 0.0f, 0.5f,
0.0f,<BR> 0.0f, 0.0f, 0.0f, 0.0f,
1.0f<BR> };<BR> //将ColorMatrix赋给ImageAttributes<BR> ImageAttributes
ImgAttr;<BR> ImgAttr.SetColorMatrix(&ClrMatrix,
ColorMatrixFlagsDefault,ColorAdjustTypeBitmap);<BR> //在矩形区域内显示jpg图像<BR> Image
img1(L "d:\\1.jpg");<BR> Point destPoints1[3] =<BR> {<BR> Point(10, 10),
Point(220, 10), Point(10, 290)<BR> };<BR> graphics.DrawImage(&img1,
destPoints1, 3);<BR> //Alpha混合<BR> Image img2(L "d:\\2.jpg");<BR> int
width, height;<BR> width = img2.GetWidth();<BR> height =
img2.GetHeight();<BR> graphics.DrawImage(&img2, RectF(10, 10, 210,
280), 0, 0, width, height,UnitPixel,
&ImgAttr);<BR> //在平行四边形区域内显示jpg图像<BR> Point destPoints2[3]
=<BR> {<BR> Point(230, 10), Point(440, 10), Point(270,
290)<BR> };<BR> graphics.DrawImage(&img1, destPoints2,
3);<BR> //Alpha混合<BR> graphics.DrawImage(&img2, destPoints2, 3, 0, 0,
width, height,
UnitPixel,&ImgAttr);<BR>}</TD></TR></TBODY></TABLE><BR> 上述程序中将D盘根目录下文件名为"1.jpg"的图像以矩阵和平行四边形两种方式显示,然后将文件名为为"2.jpg"的图像与之进行混合,其效果如图8。<BR><BR>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center><IMG
src="Windows GDI和GDI+编程实例剖析_6.files/icv0m9u6rl31.jpg" border=0><BR>图8 GDI+
Alpha混合</DIV></TD></TR></TBODY></TABLE><BR> 为了能进行Alpha混合,我们需要使用ImageAttributes类和ColorMatrix矩阵,ImageAttributes可以进行颜色、灰度等调整从而达到控制图像着色方式的目的。ColorMatrix是ImageAttributes类大多数函数的参数,它包含了Alpha、Red、Green、Blue维度的值,以及另一维w,顺序为RGBaw。<BR><BR> CGdiexampleDlg::OnAlphaBlend()函数中ColorMatrix的实例ClrMatrix中元素(4,4)的值为0.5,表示Alpha度的值为0.5(即半透明)。在ColorMatrix中,元素(5,5)的值恒定为1.0。我们把ClrMatrix的元素(0,0)修改为0.0,即使得图像2.jpg的红色维度全不显示,再看效果,为图9。列位读者,我们以前在豪杰超级解霸中调整R,G,B值从而控制图像输出颜色的时候,调的就是这个东东!图9的效果很像破旧彩色电视机,红色电子枪"嗝"了。刚大学毕业时,俺那个叫穷啊,就买了这么个电视机,还看得很爽,真是往事不堪回首!<BR><BR>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center><IMG
src="Windows GDI和GDI+编程实例剖析_6.files/q811cb0964mz.jpg" border=0><BR>图9
GDI+中的ColorMatrix</DIV></TD></TR></TBODY></TABLE><BR>
<DIV class=right>共8页。 <A class=page
href="http://tech.bc0436.com/dev/255/2190255.shtml" target=_self><FONT
face=Webdings>9</FONT></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_4.shtml" target=_self><FONT
face=Webdings>7</FONT></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255.shtml" target=_self><B>1</B></A> <A
class=page href="http://tech.bc0436.com/dev/255/2190255_1.shtml"
target=_self><B>2</B></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_2.shtml" target=_self><B>3</B></A>
<A class=page href="http://tech.bc0436.com/dev/255/2190255_3.shtml"
target=_self><B>4</B></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_4.shtml" target=_self><B>5</B></A>
<A class=page href="http://tech.bc0436.com/dev/255/2190255_5.shtml"
target=_self><FONT color=#666666><B>6</B></FONT></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_6.shtml" target=_self><B>7</B></A>
<A class=page href="http://tech.bc0436.com/dev/255/2190255_7.shtml"
target=_self><B>8</B></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_6.shtml" target=_self><FONT
face=Webdings>8</FONT></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_7.shtml" target=_self><FONT
face=Webdings>:</FONT></A></DIV></DIV>
<CENTER><A class=zhy0815button_content title=编辑推荐你阅读
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#1" target=_self>推荐阅读</A> <A
class=zhy0815button_content title=本栏目的最新更新
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#2" target=_self>最新更新</A> <A
class=zhy0815button_content title=阅读此文章的读者还看了以下文章
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#3" target=_self>继续阅读</A> <A
class=zhy0815button_content title=相关主题的关键字
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#4" target=_self>相关主题</A> <A
class=zhy0815button_content title=本文编辑方舟的其他文章
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#5" target=_self>编辑新作</A> <A
class=zhy0815button_content title=本栏目最近最受欢迎的文章
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#6" target=_self>阅读排行</A> <A
class=zhy0815button_content id=comment_url_tag title=读者、编辑互动讨论区
href="http://comments.yesky.com/t/GDI/6,324/2190255.shtml">讨论本文</A><A
class=zhy0815button_content id=comment_url_art title=读者、编辑互动讨论区
href="http://comments.yesky.com/a/6,324/2190255.shtml">讨论本文</A> <A
class=zhy0815button_content title=本文相关产品和厂商
href="http://tech.bc0436.com/dev/255/2190255_5.shtml#8" target=_self>相关产品</A>
</CENTER><!-- Error -->
<DIV class=clear1></DIV></DIV><!--结束-->
<DIV class=clear1></DIV>
<DIV class=space2><SPAN id=ad7></SPAN></DIV><!--文章评论区-->
<SCRIPT language=JavaScript>
<!--
var aid = 2190255;
var channelid = 324;
var tagname = "GDI";
//-->
</SCRIPT>
<SCRIPT language=JavaScript>
<!--
if(typeof(tagname) == "string" && tagname.length > 0) {
comment_url_art[0].style.display = "none";
comment_url_art[1].style.display = "none";
comment_url_tag[0].style.display = "";
comment_url_tag[1].style.display = "";
} else {
comment_url_art[0].style.display = "";
comment_url_art[1].style.display = "";
comment_url_tag[0].style.display = "none";
comment_url_tag[1].style.display = "none";
}
//-->
</SCRIPT>
<!--结束-->
<DIV class=clear1></DIV>
<DIV class=newxiangguan>
<DIV class=newxiangguanmenu><IMG height=11
src="Windows GDI和GDI+编程实例剖析_6.files/inverse1-dht.gif" width=22><A
name=1>推荐阅读:相关文章</A> </DIV>
<DIV class=newxiangguancontent>
<LI><A
href="http://tech.bc0436.com/387/1937387.shtml">VC++.NET的GDI+入门之位图和图标</A>(2005-04-19
16:18)
<LI><A
href="http://tech.bc0436.com/423/1937423.shtml">VC.NET的GDI+编程入门教程之图形</A>(2005-04-19
16:09)
<LI><A
href="http://tech.bc0436.com/SoftChannel/72348977504190464/20050419/1938104.shtml">基于Visual
C++.NET的GDI+编程快速入门</A>(2005-04-19 18:28)
<LI><A href="http://tech.bc0436.com/188/1951188.shtml">基于Windows
GDI+的几何线条处理</A>(2005-05-20 15:02)
<LI><A
href="http://tech.bc0436.com/dev/121/2018121.shtml">基于VC++的GDI常用坐标系统及应用</A>(2005-06-20
08:59)
<LI><A
href="http://tech.bc0436.com/dev/msdn/113/2112113.shtml">利用GDI+的双缓冲技术来提高绘图效率</A>(2005-09-12
17:01)
<LI><A
href="http://tech.bc0436.com/dev/msdn/183/2133683.shtml">托管C++中GDI+和GDI混合编程技术</A>(2005-09-26
09:16)
<LI><A
href="http://tech.bc0436.com/soft/lesson/multimedia/index.shtml">图像与多媒体编程</A>(专题)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -