绿色风's Blog
专注AutoIT(Au3)
  • 首页
  • 流●年
  • 笔●记
    • 学习随记
    • 源码示例
  • 脚●本
    • UDF(收集)
    • 工作室UDF
    • 工具●教程
    • 教程之GDI
  • 作●品
  • 下●载
  • 情怀ExcelTip
1月82015

[教程]第十二讲 GDI+路径

作者:绿色风   发布:2015-1-8 7:45 Thursday   分类:   阅读:14786次   评论:0条  

ACN论坛.讲师:seniors   转载请说明此文出处所在:<<简易工作室>>,谢谢!

GDI+路径

1、建立

_GDIPlus_PathCreate($iFillMode)

_GDIPlus_PathCreate2($aPtTypes, $iFillMode)

$iFillMode =0相当于是XOR模式, =1时相当于是OR模式

$aPtTypes是根据点来建立路径

2、路径可以变换

这里介绍一下_GDIPlus_PathWarp($hPath, $hMatrix, $aPoints, $nX, $nY, $nWidth, $nHeight, $iWarpMode = 0, $nFlatness = $FlatnessDefault)

它是指$nX, $nY, $nWidth, $nHeight矩形按 $aPoints规定的开关变形,如果有$hMatrix再按$hMatrix变化

$aPoints必须是3个点或者4个点

注意UDF中这个函数有一个地方错了,把这个If $iCount <> 3 Or $iCount <> 4 Then

改成If $iCount <> 3 And $iCount <> 4 Then

就行了

 

Func _GDIPlus_PathWarp($hPath, $hMatrix, $aPoints, $nX, $nY, $nWidth, $nHeight, $iWarpMode = 0, $nFlatness = $FlatnessDefault)
        Local $iI, $iCount, $pPoints, $tPoints, $aResult
        $iCount = $aPoints[0][0]
        If $iCount <> 3 And $iCount <> 4 Then
                $GDIP_ERROR = 1
                Return False
        EndIf
        $tPoints = DllStructCreate("float[" & $iCount * 2 & "]")
        $pPoints = DllStructGetPtr($tPoints)
        For $iI = 1 To $iCount
                DllStructSetData($tPoints, 1, $aPoints[$iI][0], ($iI - 1) * 2 + 1)
                DllStructSetData($tPoints, 1, $aPoints[$iI][1], ($iI - 1) * 2 + 2)
        Next
        $aResult = DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPath, "hwnd", $hMatrix, "ptr", $pPoints, "int", $iCount, "float", $nX, "float", $nY, "float", $nWidth, "float", $nHeight, "int", $iWarpMode, "float", $nFlatness)
        If @error Then Return SetError(@error, @extended, False)
        $GDIP_STATUS = $aResult[0]
        Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_PathWarp```
另外例子中还有路径点的读取及点坐标更改
楼上风云的写字笔顺问题,我想说下,文字的路径不是一笔一笔的,他是一块连通区域是一个路径,而且也不是按书写顺序的
如果你要自己研究的话,可以看下_GDIPlus_PathIterNextSubpathPath NewImage.png
 ```

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

GUICreate("第十二讲 GDI+路径", 500, 200)
$nCtrlId = GUICtrlCreatePic("", 0, 0, 500, 200)
$hPicWnd = GUICtrlGetHandle($nCtrlId)

GUISetState()
update()

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

Func update()
        Local $HWND_CX = _WinAPI_GetWindowWidth($hPicWnd)
        Local $HWND_CY = _WinAPI_GetWindowHeight($hPicWnd)
        _GDIPlus_Startup()
        $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hPicWnd)
        _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
        $hBitmap = _GDIPlus_BitmapCreateFromGraphics($HWND_CX, $HWND_CY, $hGraphics)
        $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
        _GDIPlus_GraphicsClear($hBackbuffer, 0xFFECE9D8)
        _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2);光滑模式,2为8*8抗距齿
        fillmodeComp($hBackbuffer)
        PathString($hBackbuffer)
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $HWND_CX, $HWND_CY)
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_GraphicsDispose($hBackbuffer)
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_Shutdown()
EndFunc   ;==>update

Func PathString($hGraphics)
        _GDIPlus_GraphicsResetTransform($hGraphics)
        Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
        Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
        Local $hFont = _GDIPlus_FontCreate($hFamily, 30, 0)
        Local $tLayout = _GDIPlus_RectFCreate(0, 0)

        Local $hPath = _GDIPlus_PathCreate()
        _GDIPlus_PathAddString($hPath, "正常文字", $tLayout, $hFamily, 0, 30)
        _GDIPlus_GraphicsTranslateTransform($hGraphics, 0, 60)
        _GraphicsFillPath($hGraphics, $hPath, $hBrush)
        _GDIPlus_PathDispose($hPath)

        Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, "平行四边形", $hFont, $tLayout, 0)
        Local $width = DllStructGetData($aInfo[0], "Width"), $height = DllStructGetData($aInfo[0], "Height")
        $hPath = _GDIPlus_PathCreate()
        _GDIPlus_PathAddString($hPath, "平行四边形", $tLayout, $hFamily, 0, 30)
        Local $aPoints[5][2] = [[4, 0], _ ;4个端点
                        [30, 0], _      ;x1, y1
                        [$width - 60, 0], _     ;x2, y2
                        [0, $height], _         ;x3, y3
                        [$width, $height]] ;x4, y4
        _GDIPlus_PathWarp($hPath, 0, $aPoints, 0, 0, $width, $height)
        _GDIPlus_GraphicsTranslateTransform($hGraphics, 150, 0)
        _GraphicsFillPath($hGraphics, $hPath, $hBrush)
        _GDIPlus_PathDispose($hPath)

        $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, "三角形变换", $hFont, $tLayout, 0)
        $width = DllStructGetData($aInfo[0], "Width")
        $height = DllStructGetData($aInfo[0], "Height")
        $hPath = _GDIPlus_PathCreate()
        _GDIPlus_PathAddString($hPath, "三角形变换", $tLayout, $hFamily, 0, 30)
        Local $bPoints[4][2] = [[3, 0], _ ;4个端点
                        [0, 0], _       ;x1, y1
                        [$width, 0], _  ;x2, y2
                        [$width / 2, $height]] ;x3, y3
        _GDIPlus_PathWarp($hPath, 0, $bPoints, 0, 0, $width, $height)
        _GDIPlus_GraphicsTranslateTransform($hGraphics, 150, 0)
        _GraphicsFillPath($hGraphics, $hPath, $hBrush)
        _GDIPlus_PathDispose($hPath)
        _GDIPlus_BrushDispose($hBrush)

        $hBrush = _GDIPlus_LineBrushCreate(0, 0, 0, 30, 0xFFFF0000, 0xFFFF6633, 1)
        _GDIPlus_GraphicsResetTransform($hGraphics)
        $hPath = _GDIPlus_PathCreate()
        _GDIPlus_PathAddString($hPath, "正弦函数曲线字符测试字符串", $tLayout, $hFamily, 0, 30)
        $hPath = sinPath($hPath)
        _GDIPlus_GraphicsTranslateTransform($hGraphics, 0, 100)
        _GraphicsFillPath($hGraphics, $hPath, $hBrush)
        _GDIPlus_PathDispose($hPath)

        $hPath = _GDIPlus_PathCreate()
        _GDIPlus_PathAddString($hPath, "抛物线函数曲线字符测试字符串", $tLayout, $hFamily, 0, 30)
        $hPath = parabolaPath($hPath)
        _GDIPlus_GraphicsTranslateTransform($hGraphics, 0, 40)
        _GraphicsFillPath($hGraphics, $hPath, $hBrush)
        _GDIPlus_PathDispose($hPath)

        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
EndFunc   ;==>PathString

;填充模式对比
Func fillmodeComp($hGraphics)
        Local $hPen = _GDIPlus_PenCreate(0xFFFF0000, 1)
        Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
        ;填充模式0
        Local $hPath = _GDIPlus_PathCreate()
        _GDIPlus_PathAddEllipse($hPath, 5, 5, 50, 50)
        _GDIPlus_PathAddEllipse($hPath, 30, 5, 50, 50)
        _GDIPlus_PathAddEllipse($hPath, 55, 5, 50, 50)
        _GDIPlus_PathAddEllipse($hPath, 80, 5, 50, 50)

        _GraphicsDrawPath($hGraphics, $hPath, $hPen)
        _GDIPlus_GraphicsTranslateTransform($hGraphics, 100, 0)
        _GraphicsFillPath($hGraphics, $hPath, $hBrush)
        _GDIPlus_PathDispose($hPath)
        _GDIPlus_GraphicsTranslateTransform($hGraphics, 150, 0)
        ;填充模式1
        $hPath = _GDIPlus_PathCreate(1)
        _GDIPlus_PathAddEllipse($hPath, 5, 5, 50, 50)
        _GDIPlus_PathAddEllipse($hPath, 30, 5, 50, 50)
        _GDIPlus_PathAddEllipse($hPath, 55, 5, 50, 50)
        _GDIPlus_PathAddEllipse($hPath, 80, 5, 50, 50)

        _GraphicsDrawPath($hGraphics, $hPath, $hPen)
        _GDIPlus_GraphicsTranslateTransform($hGraphics, 100, 0)
        _GraphicsFillPath($hGraphics, $hPath, $hBrush)
        _GDIPlus_PathDispose($hPath)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_PenDispose($hPen)
EndFunc   ;==>fillmodeComp

Func sinPath($hPath)
        Local $retPath, $x, $y
        Local $PathData = _GDIPlus_PathGetData($hPath);获取路径的点和类型的数组
        ;[0][0]是点数,[1][0] - 点1的X位置, [1][1] - 点1的Y位置,[1][2]是点1的类型
        If @error Then Return SetError(@error, @extended, 0)
        ;以下只是修改了点的Y坐标
        For $i = 1 To $PathData[0][0]
                $x = $PathData[$i][0]
                $y = $PathData[$i][1]
                $y += Sin($x / 20) * 10
                $PathData[$i][1] = $y
        Next
        $retPath = _GDIPlus_PathCreate2($PathData);根据点建立路径
        Return $retPath
EndFunc   ;==>sinPath

Func parabolaPath($hPath)
        Local $retPath, $x, $y
        Local $PathData = _GDIPlus_PathGetData($hPath)
        If @error Then Return SetError(@error, @extended, 0)
        For $i = 1 To $PathData[0][0]
                $x = $PathData[$i][0]
                $y = $PathData[$i][1]
                $yy = $y + (30 - $y) * ($x - 250) * ($x - 250) / 100000
                If $yy > 30 Then $yy = 30
                $PathData[$i][1] = $yy
        Next
        $retPath = _GDIPlus_PathCreate2($PathData)
        Return $retPath
EndFunc   ;==>parabolaPath

;_GDIPlus_GraphicsDrawString这个函数,我认为他没有设置$hBrush,所以我改成这样就可以用不同的画刷了
Func _GraphicsDrawString($hGraphics, $sString, $nX, $nY, $hBrush = 0, $sFont = "Arial", $nSize = 10, $iFormat = 0)
        Local $hFormat = _GDIPlus_StringFormatCreate($iFormat)
        Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
        Local $hFont = _GDIPlus_FontCreate($hFamily, $nSize)
        Local $tLayout = _GDIPlus_RectFCreate($nX, $nY, 0, 0)
        Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat)
        __GDIPlus_BrushDefCreate($hBrush)
        Local $aResult = _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
        Local $iError = @error
        __GDIPlus_BrushDefDispose()
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_StringFormatDispose($hFormat)
        Return SetError($iError, 0, $aResult)
EndFunc   ;==>_GraphicsDrawString

;下面这两个描路径和填充路径,在3.3.9.5中已经更正了,我用的是3.3.7.15画笔和画刷设置不对,可以改成这样的就行了
Func _GraphicsDrawPath($hGraphics, $hPath, $hPen = 0)
        Local $iTmpErr, $iTmpExt, $aResult
        __GDIPlus_PenDefCreate($hPen)
        $aResult = DllCall($ghGDIPDll, "uint", "GdipDrawPath", "hwnd", $hGraphics, "hwnd", $hPen, "hwnd", $hPath)
        $iTmpErr = @error
        $iTmpExt = @extended
        __GDIPlus_PenDefDispose()
        If $iTmpErr Then Return SetError($iTmpErr, $iTmpExt, False)
        $GDIP_STATUS = $aResult[0]
        Return $aResult[0] = 0
EndFunc   ;==>_GraphicsDrawPath

Func _GraphicsFillPath($hGraphics, $hPath, $hBrush = 0)
        Local $iTmpErr, $iTmpExt, $aResult
        __GDIPlus_BrushDefCreate($hBrush)
        $aResult = DllCall($ghGDIPDll, "uint", "GdipFillPath", "hwnd", $hGraphics, "hwnd", $hBrush, "hwnd", $hPath)
        $iTmpErr = @error
        $iTmpExt = @extended
        __GDIPlus_BrushDefDispose()
        If $iTmpErr Then Return SetError($iTmpErr, $iTmpExt, False)
        $GDIP_STATUS = $aResult[0]
        Return $aResult[0] = 0
EndFunc   ;==>_GraphicsFillPath```
    






本文固定链接: http://www.jianyiit.com/post-60.html

blogger
该日志由 绿色风 于2015-1-8 7:45 Thursday发表在 分类下。
版权所有:《绿色风's Blog》 → 《[教程]第十二讲 GDI+路径》;
除特别标注,本博客很多文章均为原创. 互联分享,尊重版权,转载请以链接形式标明本文地址;
本文标签:

扫描二维码,在手机上阅读
上一篇::[教程]第十三讲 GDI+区域及剪切区域
下一篇:[教程] 第十一讲 GDI+画笔之补充 画笔的缩放和旋转

热门文章

相关文章

  • [教程] 第十一讲 GDI+画笔及线型
  • [教程] 第十讲之分解3-纹理画刷
  • [教程]第十五讲GDI+图像之颜色矩阵
  • [教程]第十八讲 GDI+窗口自绘无控件
  • [教程]第十讲 GDI+文字,附发光字,阴影字
取消回复

发表评论

亲,头像对么?

54 + 50 =

提交中,请稍候……


木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!


    站点统计
    • 运行时间: 20254 天
    • 日志总数: 365 篇
    • 评论数量: 7238 条
    • 微语数量: 6 条
    • 附件总量: 388 件
  • 逝出的青春

  • 打赏"绿色风"



      扫码关注本站公众号 可搜本站内容

  • Autoit V3 脚本交流群

      常驻群1:905774875
      常驻群2:40672266


  • 链接

    • AU3中文论坛
    • Excel资料库
    • 完美者博客
    • 顺网小哥'S Blog
    • 猛牛哥的博客
    • 网吧系统下载
  • 分类

    • 流●年(66)
    • 笔●记(0)
    • 脚●本(0)
    • 作品(21)
    • 学习随记(51)
    • 源码示例(68)
    • UDF(收集)(26)
    • 工作室UDF(30)
    • 工具●教程(62)
    • 教程之GDI(24)
Copyright © 2013 绿色风's Blog. Powered by emlog. Theme by 射雕天龙. 鄂ICP备2021011689号-1 鄂公网安备42102302000078号 sitemap