设为首页 加入收藏

TOP

使用点,刷子,笔进行绘图
2014-11-23 20:10:20 来源: 作者: 【 】 浏览:9
Tags:使用 刷子 进行 绘图

Windows中画点的方法很简单,只需要调用COLORREF CDC::SetPixel( int x, int y, COLORREF crColor )就可以在指定点画上指定颜色,同时返回原来的颜色。COLORREF CDC::GetPixel( int x, int y)可以得到指定点的颜色。在Windows中应该少使用画点的函数,因为这样做的执行效率比较低。

刷子和画笔在Windows作图中是使用最多的GUI对象,本节在讲解刷子和画笔使用方法的同时也讲述一写基本作图函数。

在画点或画线时系统使用当前DC中的画笔,所以在创建画笔后必须将其选入DC才会在绘图时产生效果。画笔可以通过CPen对象来产生,通过调用CPen::CreatePen( int nPenStyle, int nWidth, COLORREF crColor )来创建。其中nPenStyle指名画笔的风格,可取如下值:

  • PS_SOLID 实线 Creates a solid pen.
  • PS_DASH 虚线,宽度必须为一 Creates a dashed pen. Valid only when the pen width is 1 or less, in device units.
  • PS_DOT 点线,宽度必须为一 Creates a dotted pen. Valid only when the pen width is 1 or less, in device units.
  • PS_DASHDOT 点划线,宽度必须为一 Creates a pen with alternating dashes and dots. Valid only when the pen width is 1 or less, in device units.
  • PS_DASHDOTDOT 双点划线,宽度必须为一 Creates a pen with alternating dashes and double dots. Valid only when the pen width is 1 or less, in device units.
  • PS_NULL 空线,使用时什么也不会产生 Creates a null pen.
  • PS_ENDCAP_ROUND 结束处为圆形 End caps are round.
  • PS_ENDCAP_SQUARE 结束处为方形 End caps are square.

nWidth和crColor为线的宽度和颜色。

刷子是在画封闭曲线时用来填充的颜色,例如当你画圆形或方形时系统会用当前的刷子对内部进行填充。刷子可利用CBrush对象产生。通过以下几种函数创建刷子:

  • BOOL CreateSolidBrush( COLORREF crColor ); 创建一种固定颜色的刷子
  • BOOL CreateHatchBrush( int nIndex, COLORREF crColor ); 创建指定颜色和网格的刷子,nIndex可取以下值:
    • HS_BDIAGONAL Downward hatch (left to right) at 45 degrees
    • HS_CROSS Horizontal and vertical crosshatch
    • HS_DIAGCROSS Crosshatch at 45 degrees
    • HS_FDIAGONAL Upward hatch (left to right) at 45 degrees
    • <script type="text/java script">BAIDU_CLB_fillSlot("771048");
      点击复制链接 与好友分享! 回本站首页
      <script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
      分享到: 更多
      <script type="text/java script" id="bdshare_js" data="type=tools&uid=12732"> <script type="text/java script" id="bdshell_js"> <script type="text/java script"> var bds_config = {'snsKey':{'tsina':'2386826374','tqq':'5e544a8fdea646c5a5f3967871346eb8'}}; document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js cdnversion=" + Math.ceil(new Date()/3600000)
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇进程控制 下一篇使用属性对话框

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: