找回密码
 加入
搜索
查看: 14041|回复: 8

[交流] 第五讲 GDI路径和选区

 火.. [复制链接]
发表于 2013-5-16 21:21:39 | 显示全部楼层 |阅读模式
本帖最后由 seniors 于 2013-6-16 07:55 编辑

GDI之路径、选区
一、路径
使用_WinAPI_BeginPath($hDC)开始绘制路径
最后使用_WinAPI_EndPath($hDC)结束绘制路径

路径绘制使用改变当前位置的函数,绘制路径时,在DC上没有图形
绘制路径函数有
_WinAPI_MoveTo
_WinAPI_MoveToEx
_WinAPI_LineTo
_WinAPI_ArcTo
_WinAPI_PolyBezierTo

如果绘制封闭路径
其它的绘图函数都可以
如果绘制的图形不封闭,要路径封闭还可以用
_WinAPI_CloseFigure来封闭路径
路径可以用画笔描边,使用_WinAPI_StrokePath($hDC)
封闭的路径还可以填充,使用_WinAPI_FillPath($hDC)
路径描边和填充同时进行的,使用_WinAPI_StrokeAndFillPath($hDC)
以上帮助中基本都有例子
本讲源码中用没有例子的_WinAPI_PolyDraw来绘制路径,以及看看
_WinAPI_FlattenPath($hDC);使路径平滑的作用
_WinAPI_WidenPath($hDC);扩大路径的作用

二、选区
可以看作是封闭的路径,当然路径和选区是不同的
创建选区
_WinAPI_CreateNullRgn;空选区
_WinAPI_CreateRectRgn;矩形选区
_WinAPI_CreateRoundRectRgn;圆角矩形选区
_WinAPI_CreatePolygonRgn;多边形选区
从路径转换为选区,路径必须是封闭的
_WinAPI_PathToRegion($hDC)
选区合并,有多个模式
_WinAPI_CombineRgn($hRgnDest, $hRgnSrc1, $hRgnSrc2, $iCombineMode)
当不再需要选区对象时,调用 _WinAPI_DeleteObject 函数删除它.
填充选区
_WinAPI_FillRgn
描边选区
_WinAPI_FrameRgn
时间关系选区就不做具体说明了
三、渐变填充
_WinAPI_GradientFill;水平或竖直渐变填充
_WinAPI_RadialGradientFill;径向渐变填充
这两个渐变填充,帮助例子说明的比较清晰了

另:下讲开始要让我们绘制的图案一直显示,GDI分部分到完全自绘一个地址控件为止吧,至于GDI+,等讲完了GDI再说吧
每天写比较累,自己实力也跟不上,以后不一定每天一讲
忘记布置作业了
用路径绘制一个我们发贴时引用的这个图案吧

本讲源码

#include <APIConstants.au3>
#include <WinAPIEx.au3>

GUICreate("第五讲", 300, 200)
$ctrlId = GUICtrlCreatePic("", 0, 0, 300, 200)
$hWnd = GUICtrlGetHandle($ctrlId)
GUISetState()
gditest()

While 1
        $Msg = GUIGetMsg()
        Switch $Msg
                Case -3
                        ExitLoop
        EndSwitch
WEnd
GUIDelete()
Exit

Func gditest()
        Local $aPoint[7][3] = [[90, 20, $PT_MOVETO],[50, 10, $PT_BEZIERTO],[10, 20, $PT_BEZIERTO],[50, 30, $PT_BEZIERTO],[90, 40, $PT_BEZIERTO],[50, 50, $PT_BEZIERTO],[10, 40, $PT_BEZIERTO]]
        Local $bPoint[7][3] = [[10, 50, $PT_MOVETO],[10, 10, $PT_LINETO],[50, 10, $PT_LINETO],[90, 20, $PT_BEZIERTO],[90, 40, $PT_BEZIERTO],[50, 50, $PT_BEZIERTO],[10, 50, $PT_LINETO + $PT_CLOSEFIGURE]]
        ;$PT_BEZIERTO的点至少要有3个才能绘制贝塞尔曲线
        $hDC = _WinAPI_GetDC($hWnd)
        ;设置画笔。画刷
        $hOldBrush = _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($DC_BRUSH));DC_BRUSH帮助中没看到,是在例子中看到的,晕
        $hOldPen = _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($DC_PEN));DC_PEN帮助中没看到,是在例子中看到的,晕
        _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($DEFAULT_GUI_FONT))
        _WinAPI_SetDCPenColor($hDC, 0xFF0000)
        _WinAPI_SetDCBrushColor($hDC, 0xFFFF00)
        ;不封闭路径
        _WinAPI_BeginPath($hDC)
        _WinAPI_PolyDraw($hDC, $aPoint)
        _WinAPI_EndPath($hDC)
        _WinAPI_StrokePath($hDC)

        ;路径平直化,效果不明显,应该是路径还不够复杂,平直化后路径点数会变少
        _WinAPI_BeginPath($hDC)
        _WinAPI_OffsetPoints($aPoint, 100, 0);数组各点右移100
        _WinAPI_PolyDraw($hDC, $aPoint)
        _WinAPI_EndPath($hDC)
        _WinAPI_FlattenPath($hDC);平滑路径
        _WinAPI_StrokePath($hDC)
        
        ;路径扩大,画的线变粗了
        _WinAPI_BeginPath($hDC)
        _WinAPI_OffsetPoints($aPoint, 100, 0);数组各点右移100
        _WinAPI_PolyDraw($hDC, $aPoint)
        _WinAPI_EndPath($hDC)
        _WinAPI_WidenPath($hDC);扩大路径
        _WinAPI_StrokePath($hDC)
        
        ;封闭路径
        _WinAPI_BeginPath($hDC)
        _WinAPI_OffsetPoints($bPoint, 0, 100);数组各点下移100
        _WinAPI_PolyDraw($hDC, $bPoint)
        _WinAPI_EndPath($hDC)
        _WinAPI_StrokeAndFillPath($hDC)
        
        ;路径平直化,效果不明显,应该是路径还不够复杂,平直化后路径点数会变少
        _WinAPI_BeginPath($hDC)
        _WinAPI_OffsetPoints($bPoint, 100, 0);数组各点左移100
        _WinAPI_PolyDraw($hDC, $bPoint)
        _WinAPI_EndPath($hDC)
        _WinAPI_FlattenPath($hDC);平滑路径
        _WinAPI_StrokeAndFillPath($hDC)
        
        ;对封闭路径,扩大后。只有路径不能填充
        _WinAPI_BeginPath($hDC)
        _WinAPI_OffsetPoints($bPoint, 100, 0);数组各点左移100
        _WinAPI_PolyDraw($hDC, $bPoint)
        _WinAPI_EndPath($hDC)
        _WinAPI_WidenPath($hDC);扩大路径
        _WinAPI_WidenPath($hDC);扩大路径
        _WinAPI_WidenPath($hDC);扩大路径
        _WinAPI_WidenPath($hDC);扩大路径
        _WinAPI_WidenPath($hDC);扩大路径
        _WinAPI_StrokeAndFillPath($hDC)
        
        $tRECT = _WinAPI_CreateRect(10, 70, 290, 90)
        _WinAPI_SetBkMode($hDC, $TRANSPARENT);设置文字背景透明
        _WinAPI_DrawText($hDC, "原始路径        平滑路径           扩大路径", $tRECT, $DT_LEFT);如果不哆输出省略号
        _WinAPI_ReleaseDC($hWnd, $hDC)
EndFunc   ;==>gditest

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 4威望 +3 金钱 +170 贡献 +21 收起 理由
xms77 + 50 + 2 每天一讲,每日一学
楼上风云 + 20 应酬后又错失了板凳机会,边醒酒边消化
lpxx + 50 + 14 谢谢
afan + 3 + 50 + 5 ++

查看全部评分

发表于 2013-5-16 21:44:22 | 显示全部楼层
喝酒归来,拉下两节课了,一定会补上的~
发表于 2013-5-16 22:21:03 | 显示全部楼层
感谢分享。学习了。
发表于 2013-5-16 23:27:19 | 显示全部楼层
回复 1# seniors
应酬后又错失了板凳机会,边醒酒边消化
发表于 2013-5-17 08:23:43 | 显示全部楼层
感谢分享!才开始学习!!
发表于 2013-5-17 12:26:05 | 显示全部楼层
每天一讲,每日一学~
发表于 2013-7-27 10:36:15 | 显示全部楼层
先收藏,循序渐进。
发表于 2015-9-3 13:44:06 | 显示全部楼层
感谢分享。学习了。
发表于 2022-10-18 21:38:27 | 显示全部楼层
慢慢学习 谢谢大师
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-20 20:59 , Processed in 0.081781 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表