📄 用visual c++_net进行gdi+编程 _2.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=(0048)http://www.qqread.com/vcdotnet/d652242000_2.html -->
<HTML lang=zh xml:lang="zh" xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>用Visual C++.NET进行GDI+编程 - QQread.com 电脑频道</TITLE>
<META http-equiv=Content-Language content=zh-CN>
<META
content=[art_mtkw],电脑入门,上网指南,操作系统,常用软件,黑客与安全,网络游戏,程序开发,数据库开发,网页制作,图像处理,多媒体制作,网络编程,加密技术,网络技术
name=keywords>
<META content="用Visual C++.NET进行GDI+编程" name=description>
<META content=QQRead.com name=author>
<META content=all name=robots>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK
href="用Visual C++_NET进行GDI+编程 _2.files/qqread_html.css" type=text/css
rel=stylesheet><LINK href="用Visual C++_NET进行GDI+编程 _2.files/qqread_html_com.css"
type=text/css rel=stylesheet>
<STYLE type=text/css>.STYLE2 {
FONT-SIZE: 14px
}
</STYLE>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY><!-- 公共页头 -->
<DIV style="TEXT-ALIGN: center">
<DIV id=topad>
<TABLE>
<TBODY>
<TR>
<TD width=10><SPAN
id=ad_qqread_top></SPAN><!--End//--></TD></TR></TBODY></TABLE></DIV>
<DIV id=CHBig>
<DIV id=CHBigCSDNLogo><A href="http://www.qqread.com/"><IMG alt=巧巧读书网
src="用Visual C++_NET进行GDI+编程 _2.files/qqread.gif" border=0></A></DIV>
<DIV id=CHBigHeaderWrapper>
<DIV id=CHBigNavBar2>
<UL>
<LI><A href="http://www.qqread.com/news/" target=_blank>新闻中心</A>|
<LI><A href="http://www.qqread.com/skill/" target=_blank>技巧集锦</A>|
<LI><A href="http://www.qqread.com/itlife/" target=_blank>IT人生雨露</A>|
<LI><A href="http://www.qqread.com/pcbase/" target=_blank>电脑入门</A>|
<LI><A href="http://www.qqread.com/netreference/" target=_blank>上网指南</A>|
<LI><A href="http://www.qqread.com/safe/" target=_blank>黑客与安全</A>|
<LI><A href="http://www.qqread.com/commentsoft/" target=_blank>常用软件</A>|
<LI><A href="http://www.qqread.com/os/" target=_blank>操作系统</A>|
<LI><A href="http://www.qqread.com/netgame/" target=_blank>网络游戏</A><BR>
<LI><A title=图片欣赏 href="http://www.qqread.com/photo/index.html"
target=_blank>图片欣赏</A>|
<LI><A href="http://www.qqread.com/program/" target=_blank>程序开发</A>|
<LI><A href="http://www.qqread.com/database/" target=_blank>数据库开发</A>|
<LI><A href="http://www.qqread.com/webdesign/" target=_blank>网页制作</A>|
<LI><A href="http://www.qqread.com/photohandle/" target=_blank>图像处理</A>|
<LI><A href="http://www.qqread.com/mutimedia/" target=_blank>多媒体制作</A>|
<LI><A href="http://www.qqread.com/netprogram/" target=_blank>网络编程</A>|
<LI><A href="http://www.qqread.com/encrypt/" target=_blank>加密技术</A>|
<LI><A href="http://www.qqread.com/network/" target=_blank>网络技术</A>
</LI></UL></DIV>
<DIV id=CHBigNavBar1></DIV></DIV>
<DIV style="CLEAR: both"></DIV></DIV></DIV><!-- /公共页头 -->
<DIV id=OutBox>
<DIV id=listMainArea>
<DIV id=disclaimer><A href="http://www.qqread.com/">巧巧读书首页</A> > <A
title=程序开发 href="http://www.qqread.com/program/index.html">程序开发</A> > <A
title=.Net技术 href="http://www.qqread.com/dotnet/index.html">.Net技术</A> > <A
title=VC.NET href="http://www.qqread.com/vcdotnet/index.html">VC.NET</A> >
正文</DIV>
<DL class=ReadArticle>
<DT>用Visual C++.NET进行GDI+编程
<DD class=ArticleInfo3>
<SCRIPT src="用Visual C++_NET进行GDI+编程 _2.files/adtitle.js"
type=text/javascript></SCRIPT>
<HR SIZE=2>
<DD class=ArticleInfo3>
<DIV align=center><A href="http://www.qqread.com/">http://www.qqread.com/</A>
作者:ADDING 2006-01-24 来源:yesky 浏览:<SPAN id=count></SPAN> </DIV>
<DD class=ArticleInfo_3>
<DD class=ArticleInfo_3><A
href="http://www.qqread.com/vcdotnet/d652242000.html">上一页</A> <A
href="http://www.qqread.com/vcdotnet/d652242000.html">1</A> <FONT
color=#ff0000>2</FONT> <A
href="http://www.qqread.com/vcdotnet/d652242000_3.html">3</A> <A
href="http://www.qqread.com/vcdotnet/d652242000_3.html">下一页</A>
<DD
class=ArticleContent><B>GDI+编程模块的变化</B><BR><BR> 为了简化GDI+的编程开发过程,Microsoft对GDI+的编程模块作了一些调整,这主要体现在以下几个方面:<BR><BR> 1、不再使用设备环境或句柄<BR><BR>
<TABLE style="MARGIN: 10px 8px 3px 7px" cellSpacing=0 cellPadding=0 align=left
border=0>
<TBODY>
<TR>
<TD><SPAN
id=ad_qqread_mid_big></SPAN></TD></TR></TBODY></TABLE> 我们知道,在使用GDI绘图时,必须要指定一个设备环境(DC)。<A
href="http://www.qqread.com/keywords/mfc.html"
target=_blank>MFC</A>为设备环境提供了许多由基类CDC派生的设备环境类,如CPaintDC、CClientDC和CWindowDC等,用来将某个窗口或设备与设备环境类的句柄指针关联起来,所有的绘图操作都与该句柄有关。而GDI+不再使用这个设备环境或句柄,取而代之是使用Graphics对象。<BR><BR> 与设备环境相类似,Graphics对象也是将屏幕的某一个窗口与之相关联,并包含绘图操作所需要的相关属性。但是,只有这个Graphics对象与设备环境句柄还存在着联系,其余的如Pen、Brush、Image和Font等对象均不再使用设备环境。<BR><BR> 2、绘图方式的变化<BR><BR> 先来看看同样绘制一条从点(20,
10)到点(200,
100)直线的GDI和GDI+代码,假设这些代码都是添加在OnDraw函数中。<BR><BR> GDI绘制该直线的代码如下:<BR><BR>
<TABLE width="100%" bgColor=#ffffff>
<TBODY>
<TR>
<TD>void CMyView::OnDraw(CDC* pDC)<BR>{<BR> CMyDoc* pDoc =
GetDocument();<BR> ASSERT_VALID(pDoc);<BR> CPen newPen( PS_SOLID, 3,
RGB(255, 0, 0) );<BR> CPen* pOldPen = pDC->SelectObject( &newPen
);<BR> pDC->MoveTo( 20, 10 );<BR> pDC->LineTo( 200,
100);<BR> pDC->SelectObject( pOldPen
);<BR>}</TD></TR></TBODY></TABLE><BR> GDI+绘制该直线的代码如下:<BR><BR>
<TABLE width="100%" bgColor=#ffffff>
<TBODY>
<TR>
<TD>void CMyView::OnDraw(CDC* pDC)<BR>{<BR> CMyDoc* pDoc =
GetDocument();<BR> ASSERT_VALID(pDoc);<BR> using namespace Gdiplus; //
使用名称空间<BR> Graphics graphics( pDC->m_hDC );<BR> Pen newPen( Color(
255, 0, 0 ), 3 );<BR> graphics.DrawLine(&newPen, 20, 10, 200,
100);<BR>}</TD></TR></TBODY></TABLE><BR> 从上面代码可以看出,GDI先创建一个CPen(画笔)对象,然后通过SelectObject将该画笔选入到设备环境(pDC)中。接下来调用相应的画线函数,最后恢复设备环境中原来的GDI对象。而GDI+是先使用Graphics类创建一个与pDC设备环境相关联的Graphics对象,然后使用Pen类进行画笔的创建,最后调用相应的画线方法。由于Pen和设备环境是相互独立的,因而不需要像GDI那样恢复设备环境中原来的设置,而且Pen和Graphics对象的创建不存在先后次序。<BR><BR> 2、Graphics绘图方法直接将Pen、Brush等对象作为自己的参数<BR><BR> 从上面的代码可以看出,Graphics绘图方法直接将Pen对象作为自己的参数,从而避免了在GDI使用SelectObject进行繁琐的切换,类似的还有Brush、Path、Image和Font等。<BR><BR> 3、不再使用"当前位置"<BR><BR> 我们知道,GDI绘图操作(如画线)中总存在一个被称为"当前位置"的特殊位置。每次画线都是以此当前位置为起始点,画线操作结束之后,直线的结束点位置又成为了当前位置。设置当前位置的理由是为了提高画线操作的效率,因为在一些场合下,总是一条直线连着另一条直线,首尾相接。有了当前位置的自动更新,就可避免每次画线时都要给出两点的坐标。尽管有其必要性,但是单独绘制一条直线的场合总是比较多的,因此GDI+取消这个"当前位置"以避免当无法确定"当前位置"时所造成的绘图的差错,取而代之的是直接在DrawLine中指定直线起止点的坐标。<BR><BR> 4、形状轮廓绘制和填充采用不同的方法<BR><BR> GDI总是让形状轮廓绘制和填充使用同一个绘图函数,例如Rectangle。我们知道,轮廓绘制需要一个画笔,而填充一个区域需要一个画刷。也就是说,不管我们是否需要填充所绘制的形状,我们都需要指定一个画刷,否则GDI采用默认的画刷进行填充。这种方式确实给我们带来了许多不便,现在GDI+将形状轮廓绘制和填充操作分开而采用不同的方法,例如DrawRectangle和FillRectangle分别用来绘制和填充一个矩形。<BR><BR> 5、简化区域的创建<BR><BR> 我们知道,GDI提供了许多区域创建函数,如CreateRectRgn、CreateEllpticRgn、CreateRoundRectRgn、CreatePolygonRgn和CreatePolyPolygonRgn等。诚然,这些函数给我们带来了许多方便。但在GDI+中,由于为了便于将区域引入矩阵变换操作,GDI+简化一般区域创建的方法,而将更复杂的区域创建交由Path接管。由于Path对象是与设备环境分离开来的,因而可以直接在Region构造函数中加以指定。
<DD class=ArticleContent>关键字: <A
href="http://www.qqread.com/keywords/image-processing.html">图像处理</A> <A
href="http://www.baidu.com/baidu?tn=jkday2000&word=设计">设计</A> <A
href="http://www.qqread.com/keywords/operating-system.html">操作系统</A> <A
href="http://www.qqread.com/keywords/word.html">word</A> <A
href="http://www.qqread.com/keywords/windows.html">windows</A> <A
href="http://www.qqread.com/keywords/visualcpp.html">visual
c++</A> <A
href="http://www.baidu.com/baidu?tn=jkday2000&word=PDA">pda</A> <A
href="http://www.qqread.com/keywords/os.html">os</A> <A
href="http://www.qqread.com/keywords/mfc.html">mfc</A> <A
href="http://www.qqread.com/keywords/ie.html">ie</A>
<DD class=ArticleInfo_3><A
href="http://www.qqread.com/vcdotnet/d652242000.html">上一页</A> <A
href="http://www.qqread.com/vcdotnet/d652242000.html">1</A> <FONT
color=#ff0000>2</FONT> <A
href="http://www.qqread.com/vcdotnet/d652242000_3.html">3</A> <A
href="http://www.qqread.com/vcdotnet/d652242000_3.html">下一页</A> </DD></DL>
<DIV id=ArticleContent4>
<SCRIPT src="用Visual C++_NET进行GDI+编程 _2.files/adend.js"
type=text/javascript></SCRIPT>
</DIV>
<TABLE style="MARGIN-BOTTOM: 5px" cellSpacing=1 cellPadding=0 width=582
align=center bgColor=#235f99 border=0>
<TBODY>
<TR bgColor=#ffffff>
<TD bgColor=#ffffff>
<SCRIPT src="用Visual C++_NET进行GDI+编程 _2.files/580.js"
type=text/javascript></SCRIPT>
<TR bgColor=#ffffff>
<TD bgColor=#ffffff><IFRAME marginWidth=0 marginHeight=0
src="用Visual C++_NET进行GDI+编程 _2.files/CAUDJ1G8.htm" frameBorder=0
width=580 scrolling=no height=145></IFRAME>
<TR bgColor=#ffffff>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width=580 border=0>
<TBODY>
<TR>
<TD style="PADDING-LEFT: 20px" width=266 bgColor=#235f99><B><FONT
color=#ffffff>相关文章</FONT></B></TD>
<TD style="PADDING-LEFT: 2px" bgColor=#235f99><B><FONT
color=#ffffff></FONT><FONT color=#ffffff>热点排行:</FONT></B></TD>
<TD style="PADDING-LEFT: 5px" width=189 bgColor=#235f99>
<SCRIPT language=JavaScript
src="用Visual C++_NET进行GDI+编程 _2.files/move.js"
type=text/javascript></SCRIPT>
</TD></TR>
<TR>
<TD
style="PADDING-RIGHT: 6px; PADDING-LEFT: 6px; PADDING-BOTTOM: 6px; LINE-HEIGHT: 22px; PADDING-TOP: 6px"
vAlign=top width=274>·<A title="C++ Builder与Visual C++孰优孰劣"
href="http://www.qqread.com/itlife/p011181002.html"
target=_blank>C++ Builder与Visual C++孰优孰劣</A><BR>·<A
title="eMbedded Visual C++开发入门"
href="http://www.qqread.com/other-devtool/x782130800.html"
target=_blank>eMbedded Visual C++开发入门</A><BR>·<A
title="Visual C++常微分方程初值问题求解"
href="http://www.qqread.com/vc/i602137200.html" target=_blank>Visual
C++常微分方程初值问题求解</A><BR>·<A title="Visual C++常用数据类型转换详解"
href="http://www.qqread.com/cpp/i902235300.html"
target=_blank>Visual C++常用数据类型转换详解</A><BR>·<A
title="Visual C++程序设计中的文件操作"
href="http://www.qqread.com/vc/i120830020.html" target=_blank>Visual
C++程序设计中的文件操作</A><BR>·<A title="Visual C++初学者入门的一条捷径"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -