﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-deepway</title><link>http://www.cppblog.com/maxime/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 07 Apr 2026 07:47:16 GMT</lastBuildDate><pubDate>Tue, 07 Apr 2026 07:47:16 GMT</pubDate><ttl>60</ttl><item><title>GraphicsContext的接口定义</title><link>http://www.cppblog.com/maxime/archive/2011/09/14/155752.html</link><dc:creator>maxime</dc:creator><author>maxime</author><pubDate>Wed, 14 Sep 2011 06:27:00 GMT</pubDate><guid>http://www.cppblog.com/maxime/archive/2011/09/14/155752.html</guid><description><![CDATA[GraphicsContext 定义了绘图操作环境。<br />A。基本功能是绘图操作：<br />&nbsp;&nbsp;&nbsp;1. 简单几何图形：drawRect，drawLine，drawEllipse，drawConvexPolygon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;，strokeArc，fillRect，fillRoundedRect，strokeRect，clearRect。<br />&nbsp;&nbsp;&nbsp;2. 路径：drawPath，fillPath，strokePath。<br />&nbsp;&nbsp;&nbsp;3. 图像：drawImage，drawTiledImage，drawImageBuffer。<br />&nbsp;&nbsp;&nbsp;4. 文本：drawText，drawBidiText，drawHighlightForText，drawLineForText。<br />B。路径操作：<br />C。剪切操作：<br />D。绘图参数状态配置：<br />&nbsp;&nbsp;&nbsp;1. 线条：strokeThickness，strokeStyle，strokeColor，strokeColorSpace，strokePattern，strokeGradient；<br />&nbsp;&nbsp;&nbsp;2. 填充：fillRule，fillColor，fillColorSpace，fillPattern，fillGradient；<br />&nbsp;&nbsp; 3. 品质：shouldAntialias，imageInterpolationQuality，textDrawingMode；<br />&nbsp;&nbsp;&nbsp;4. 状态：paintingDisabled；<br />E。绘图参数状态堆栈操作：<br /><br />我们可以看出，绘图操作的大部分属性参数都是通过GraphicsContext的状态传递的。<br />那么，从性能的角度考虑，这样做好么，还是直接通过函数参数传递更好呢？<br /><br />通过参数传递会带来一次参数出入堆栈操作；<br />通过GraphicsContext的状态传递，则会在每次参数变更时，进行一次参数出入堆栈操作和保存参数到状态的操作。<br />因此，当大多数绘图操作共用相同参数时，GraphicsContext的状态传递更加高效。<br /><br />当然，还要考虑到GraphicsContext的状态栈操作会在每次场景切换是带来的额外开销。<br /><img src ="http://www.cppblog.com/maxime/aggbug/155752.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maxime/" target="_blank">maxime</a> 2011-09-14 14:27 <a href="http://www.cppblog.com/maxime/archive/2011/09/14/155752.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>