找回密码
 加入
搜索
查看: 2611|回复: 7

[图形处理] 有偿请帮忙:提取代码中的图形部分

  [复制链接]
发表于 2017-6-30 14:36:49 | 显示全部楼层 |阅读模式
本帖最后由 joint 于 2017-6-30 14:54 编辑

新人新手,也不知道出多少钱合适,或者愿意帮忙的私信给我也可以。
有三段代码,想把其中的图形部分提取出来单独使用。比如下面这段代码中是有4个彩色小球。
参数有:大小、颜色、运动轨迹。简化为一个可改变大小、颜色、运动的小球即可。就是说提供一个有三个参数的可以绘制小球的函数。
第一段代码:
;coded by UEZ build 2014-04-28, idea taken from http://codepen.io/noahblon/pen/KwiFg
;AutoIt v3.3.9.21 or higher needed!

#include <Array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172; $IMAGE_BITMAP = 0
Global $iW = 600, $iH = 300
Global Const $hGUI = GUICreate("Carousel", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW, $iH)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()

Global $hHBmp_BG, $hB, $iPerc = 0, $iSleep = 10, $iPerc = 0
GUIRegisterMsg($WM_TIMER, "PlayAnim")
DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iSleep, "int", 0)

Do
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        GUIRegisterMsg($WM_TIMER, "")
                        _WinAPI_DeleteObject($hHBmp_BG)
                        _GDIPlus_Shutdown()
                        GUIDelete()
                        Exit
        EndSwitch
Until False

Func PlayAnim()
        $hHBmp_BG = _GDIPlus_Carousel($iPerc, $iW, $iH)
        $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG)
        If $hB Then _WinAPI_DeleteObject($hB)
        _WinAPI_DeleteObject($hHBmp_BG)
        $iPerc += 0.2
        If $iPerc > 99.9 Then $iPerc = 0
EndFunc   ;==>PlayAnim


Func _GDIPlus_Carousel($fPerc, $iW, $iH, $bHBitmap = True)
        Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
        Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
        _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4 + (@OSBuild > 5999))
;~         _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 3)
        _GDIPlus_GraphicsSetPixelOffsetMode($hGfx, 4)
        _GDIPlus_GraphicsClear($hGfx, 0xFFFFFFFF)

        Local Const $iUB = 4
        Local $aColors[$iUB][4] = [[0xD8F4B401, 0xE8CF9902], [0xD8E3746C, 0xE8C1645C], [0xD83A7BF9, 0xE8326AD4], [0xD8109D59, 0xE80E864C]]
        Local Const $fRadius = 50, $fMid = ($iW - $fRadius) / 2
        Local Const $hBrush = _GDIPlus_BrushCreateSolid(), $hPen = _GDIPlus_PenCreate(0x80000000)
        Local Const $hPath1 = _GDIPlus_PathCreate(), $hPath2 = _GDIPlus_PathCreate()
        Local $hRegion1, $hRegion2, $fPenSize, $i
        Local Static $fSpeed

        For $i = 0 To $iUB - 1
                $aColors[$i][2] = -Sin($fSpeed + $i * 1.570796) * 15                                ;z coordinate, 1.570796 = Pi/2 = 90?= 360?/ 4
                $aColors[$i][3] = $fMid + Cos($fSpeed + $i * 1.570796) * 80                        ;x coordinate
        Next
        _ArraySort($aColors, 0, 0, 0, 2) ;sort z-axis
        For $i = 0 To $iUB - 1
                $fPenSize = $aColors[$i][2] / 20 + 1.1
                _GDIPlus_PenSetWidth($hPen, $fPenSize)
                _GDIPlus_BrushSetSolidColor($hBrush, 0x80E0E0E0) ;shadow color
                _GDIPlus_GraphicsFillEllipse($hGfx, $aColors[$i][3], ($iH - $fRadius) / 2 + 10 + $fRadius + $aColors[$i][2], $fRadius + $aColors[$i][2], ($fRadius + $aColors[$i][2]) / 4, $hBrush)

                _GDIPlus_PathAddEllipse($hPath1, $aColors[$i][3], ($iH - $fRadius) / 2, $fRadius + $aColors[$i][2], $fRadius + $aColors[$i][2])
                _GDIPlus_PathAddEllipse($hPath2, $aColors[$i][3] + $fPenSize - 5 - $aColors[$i][2] / 10, ($iH - $fRadius) / 2 - $fPenSize - 5 - $aColors[$i][2] / 10, $fRadius + $aColors[$i][2], $fRadius + $aColors[$i][2])

                $hRegion1 = _GDIPlus_RegionCreateFromPath($hPath1)
                $hRegion2 = _GDIPlus_RegionCreateFromPath($hPath2)
                _GDIPlus_RegionCombineRegion($hRegion1, $hRegion2, 1) ;combine lighter circle with darker circle

                _GDIPlus_BrushSetSolidColor($hBrush, $aColors[$i][1]) ;lighter ball color
                _GDIPlus_GraphicsFillPath($hGfx, $hPath1, $hBrush)

                _GDIPlus_BrushSetSolidColor($hBrush, $aColors[$i][0]) ;darker ball color
                _GDIPlus_GraphicsFillRegion($hGfx, $hRegion1, $hBrush)

                _GDIPlus_GraphicsDrawPath($hGfx, $hPath1, $hPen) ;draw circle frame

                _GDIPlus_RegionDispose($hRegion1)
                _GDIPlus_RegionDispose($hRegion2)
                _GDIPlus_PathReset($hPath1)
                _GDIPlus_PathReset($hPath2)
        Next
        $fSpeed += 0.0261799

        Local $iW_Progressbar = $iW / 2 + 4
        _GDIPlus_PenSetColor($hPen, 0xD048D1CC)
        _GDIPlus_GraphicsDrawRect($hGfx, ($iW - $iW_Progressbar) / 2, $iH - 50, $iW_Progressbar, 14, $hPen)
        _GDIPlus_BrushSetSolidColor($hBrush, 0xFFAFEEEE)
        _GDIPlus_GraphicsFillRect($hGfx, ($iW - $iW_Progressbar) / 2 + 2, $iH - 48, $fPerc * ($iW_Progressbar - 4) / 100, 10, $hBrush)

        _GDIPlus_PenSetColor($hPen, 0x20000000)
        _GDIPlus_GraphicsDrawRect($hGfx, 0, 0, $iW, $iH, $hPen) ;draw window frame

        _GDIPlus_PathDispose($hPath1)
        _GDIPlus_PathDispose($hPath2)
        _GDIPlus_PenDispose($hPen)
        _GDIPlus_BrushDispose($hBrush)

        _GDIPlus_GraphicsDispose($hGfx)

        If $bHBitmap Then
                Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
                _GDIPlus_BitmapDispose($hBitmap)
                Return $hHBITMAP
        EndIf
        Return $hBitmap
EndFunc
 楼主| 发表于 2017-6-30 14:43:11 | 显示全部楼层
第二段代码:
这段代码图形是长方形的,运动方面主要是大小的变化,比前面的代码运动轨迹要简单:
;coded by UEZ build 2014-03-04, idea taken from http://codepen.io/Fahrenheit/pen/Kbyxu
;AutoIt v3.3.9.21 or higher needed!
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172; $IMAGE_BITMAP = 0
Global $iW = 400, $iH = 150
Global Const $hGUI = GUICreate("Multi Color Loader", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW, $iH)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()

Global $hHBmp_BG, $hB, $iPerc = 0, $iSleep = 30, $s = 0, $t, $m = 0, $iPerc = 0
GUIRegisterMsg($WM_TIMER, "PlayAnim")
DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iSleep, "int", 0)

Do
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        GUIRegisterMsg($WM_TIMER, "")
                        _WinAPI_DeleteObject($hHBmp_BG)
                        _GDIPlus_Shutdown()
                        GUIDelete()
                        Exit
        EndSwitch
Until False

Func PlayAnim()
        $hHBmp_BG = _GDIPlus_MultiColorLoader($iPerc, $iW, $iH, "LOADING")
        $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG)
        If $hB Then _WinAPI_DeleteObject($hB)
        _WinAPI_DeleteObject($hHBmp_BG)
        $iPerc += 0.1
        If $iPerc > 99.9 Then $iPerc = 0
EndFunc   ;==>PlayAnim


Func _GDIPlus_MultiColorLoader($iPerc, $iW, $iH, $sText = "Loading", $sFont = "Impact", $bHBitmap = True)
        Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
        Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
        _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4 + (@OSBuild > 5999))
        _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 3)
        _GDIPlus_GraphicsSetPixelOffsetMode($hGfx, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
        _GDIPlus_GraphicsClear($hGfx, 0xFF212121)

        Local Const $hPath = _GDIPlus_PathCreate()
        Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont)
        Local $tLayout = _GDIPlus_RectFCreate()
        _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily)
        Local Const $aBounds = _GDIPlus_PathGetWorldBounds($hPath)
        Local Const $hMatrix = _GDIPlus_MatrixCreate()
        _GDIPlus_MatrixTranslate($hMatrix, -$aBounds[0], -$aBounds[1])
        _GDIPlus_MatrixScale($hMatrix, $iW / $aBounds[2], $iH / $aBounds[3], True)
        _GDIPlus_PathTransform($hPath, $hMatrix)


        Local Const $hBrush_Text = _GDIPlus_BrushCreateSolid(0xFF2F2F2F), $hPen_Text = _GDIPlus_PenCreate(0xFF2C2C2C)
        Local Const $hBitmap_Fill = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
        Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_Fill)
        _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $iPerc / 100 * $iW, $iH, $hBrush_Text)
        Local Const $hTexture = _GDIPlus_TextureCreate($hBitmap_Fill)

        _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hTexture)
        _GDIPlus_GraphicsDrawPath($hGfx, $hPath, $hPen_Text)
        _GDIPlus_BrushDispose($hBrush_Text)
        _GDIPlus_PenDispose($hPen_Text)
        _GDIPlus_PathDispose($hPath)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_BrushDispose($hTexture)
        _GDIPlus_GraphicsDispose($hCtxt)
        _GDIPlus_BitmapDispose($hBitmap_Fill)

        Local Const $iColors = 7
        Local Const $aColors[$iColors] = [0xFF2ECC71, 0xFF3498DB, 0xFF9B59B6, 0xFFE67E22, 0xFFC0392B, 0xFFE74C3C, 0xFFE74C8C]
        Local Const $hBrush = _GDIPlus_BrushCreateSolid()
        Local Const $iWidth = 10, $iSpace = 4, $iX = ($iW - $iColors * ($iWidth + $iSpace)) / 2, $iHeight = $iH / 5
        Local $i, $fDH
        Local Static $s, $t
        For $i = 0 to UBound($aColors) - 1
                _GDIPlus_BrushSetSolidColor($hBrush, $aColors[$i])
                $fDH = Sin($s + Cos($i + $t)) * $iHeight * 0.66666
                _GDIPlus_GraphicsFillRect($hGfx, $iX + $i * ($iWidth + $iSpace), (-$iHeight + $iH - $fDH) / 2, $iWidth, $iHeight + $fDH, $hBrush)
                $s += 0.05
        Next
        $t += 0.1
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_GraphicsDispose($hGfx)

        If $bHBitmap Then
                Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
                _GDIPlus_BitmapDispose($hBitmap)
                Return $hHBITMAP
        EndIf
        Return $hBitmap
EndFunc
 楼主| 发表于 2017-6-30 14:47:02 | 显示全部楼层
第三段代码:
这个是余辉效果。取得图形的余辉效果函数,参数是形状、颜色、余辉衰减速度。
;by Eukalyptus
;AutoIt v3.3.9.21 or higher needed!
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172
Global $iW = 380, $iH = 260
Global $hGui = GUICreate("Loading", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
Global $cPic = GUICtrlCreatePic("", 0, 0, $iW, $iH)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()

Global $hHBmp_BG, $hB, $iPerc = 0, $iSleep = 20, $fPower = 4

GUIRegisterMsg($WM_TIMER, "PlayAnim")
DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGui, "int", 0, "int", $iSleep, "int", 0)

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_TIMER, "")
            _WinAPI_DeleteObject($hHBmp_BG)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
Until False

Func PlayAnim()
    $hHBmp_BG = _GDIPlus_SpinningAndGlowing($iPerc, $iW, $iH)
    $hB = GUICtrlSendMsg($cPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
    $iPerc += $fPower
EndFunc   ;==>PlayAnim


Func _GDIPlus_SpinningAndGlowing($fProgress, $iW, $iH, $iColor = 0xFF6644FF, $fSize = 80, $iCnt = 24, $fDM = 24, $fScale = 3, $iGlowCnt = 6)
    Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx, 2)
    _GDIPlus_GraphicsClear($hGfx, 0xFF141414)

    Local $iOff = $iCnt * Mod($fProgress, 100) / 100
    Local $fCX = $iW * 0.5
    Local $fCY = $iH * 0.5

    Local $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddEllipse($hPath, -$fDM * 0.5, -$fDM * 0.5, $fDM, $fDM)
    Local $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath)
    _GDIPlus_PathBrushSetCenterColor($hBrush, $iColor)
    _GDIPlus_PathBrushSetSurroundColor($hBrush, 0)
    _GDIPlus_PathBrushSetGammaCorrection($hBrush, True)

    Local $aBlend[5][2] = [[4]]
    $aBlend[1][0] = 0
    $aBlend[1][1] = 0
    $aBlend[2][0] = BitOR(BitAND($iColor, 0x00FFFFFF), 0x1A000000)
    $aBlend[2][1] = 0.78
    $aBlend[3][0] = BitOR(BitAND($iColor, 0x00FFFFFF), 0xFF000000)
    $aBlend[3][1] = 0.88
    $aBlend[4][0] = 0xFFFFFFFF
    $aBlend[4][1] = 1
    _GDIPlus_PathBrushSetPresetBlend($hBrush, $aBlend)

    Local $fS
    Local Const $cPI = ATan(1) * 4
    For $i = 0 To $iCnt - 1
        $fS = Sin($cPI * Log(1.4 + Mod($iOff + $i, $iCnt) / $iGlowCnt) / Log(4))
        If $fS < 0 Then $fS = 0
        $fS = 1 + $fScale * $fS

        _GDIPlus_GraphicsResetTransform($hGfx)
        _GDIPlus_GraphicsScaleTransform($hGfx, $fS, $fS, True)
        _GDIPlus_GraphicsTranslateTransform($hGfx, -$fSize, 0, True)
        _GDIPlus_GraphicsScaleTransform($hGfx, 1.2, 1, False)
        _GDIPlus_GraphicsRotateTransform($hGfx, -360 / $iCnt * $i, True)
        _GDIPlus_GraphicsTranslateTransform($hGfx, $fCX, $fCY, True)

        _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hBrush)
    Next

    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PathDispose($hPath)


    Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_BitmapDispose($hBmp)
    Return $hHBITMAP
EndFunc   ;==>_GDIPlus_SpinningAndGlowing
 楼主| 发表于 2017-7-1 11:41:19 | 显示全部楼层
本帖最后由 joint 于 2017-7-1 11:48 编辑

是不是可以直接用字符图案代替图形的绘制啊?
各种字符图案代码
http://www.360doc.com/content/14/0105/15/9708896_342803932.shtml

⊙●○①⊕◎Θ⊙¤㊣★☆♀◆◇◣◢◥▲▼△▽⊿◤ ◥ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ■ ▓ 回 □ 〓≡ ╝╚╔ ╗╬ ═ ╓ ╩ ┠ ┨┯ ┷┏ ┓┗ ┛┳⊥﹃﹄┌ ┐└ ┘∟「」↑↓→←↘↙♀♂┇┅ ﹉﹊﹍﹎╭ ╮╰ ╯ *^_^* ^*^ ^-^ ^_^ ^︵^ ∵∴‖︱ ︳︴﹏﹋﹌︵︶︹︺ 【】〖〗@﹕﹗/ " _ < > `,·。≈{}~ ~() _ -『』√ $ @ * & # ※ 卐 々∞Ψ ∪∩∈∏ ﹣±/=∫∮∝ ∞ ∧∨ ∑ ∏ ∥∠ ≌ ∽ ≦ ≧ ≒﹤﹥じ☆veve↑↓⊙●★☆■♀◆◣◥▲ ※◤ ◥ →№←㊣⌒〖〗@∮〓※∴ぷ▂▃▅▆█ 【】△√ ∩¤々♀♂∞①ㄨ≡↘↙▂ ▂ ▃ ▄ ▅ ▆ ▇ █┗┛╰—~‖…‘’“”〔〕〈 〉《》「」『』〖〗【】±+-×÷∧∨∑∏∪∩∈√⊥∥∠⌒⊙∫∮≡≌≈∽∝≠≮≯≤≥∞∶∵∴∷♂♀°′″℃$¤¢£‰§№☆★〇○●◎◇◆ 回□■△▽⊿▲▼◣◤◢◥▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▓※→←↑↓↖↗↘↙〓ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹ①②③④⑤⑥⑦⑧⑨⑩⒈⒉⒊⒋ ⒌⒍⒎⒏⒐⒑⒒⒓⒔⒕⒖⒗⒘⒙⒚⒛⑴⑵⑶⑷⑸⑹⑺⑻⑼⑽⑾⑿⒀⒁⒂⒃⒄⒅⒆⒇㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ!"#¥%&'()*+,-./0123456789:;<=>?@ABCDEFGH IJKLMNOPQRSTUVWXYZ
发表于 2017-7-1 12:24:09 | 显示全部楼层
控件字体设成webdings,应该可以吧,动态改变label内容,图案也相应的发生变化,不需要代码.只是正常的文字转成webdings,可能需要去查一下.
 楼主| 发表于 2017-7-1 12:44:38 | 显示全部楼层
控件字体设成webdings,应该可以吧,动态改变label内容,图案也相应的发生变化,不需要代码.只是正常的文字转成 ...
tubaba 发表于 2017-7-1 12:24


是啊,要是这样的话就可以简单一些了,不然绘图是件麻烦事。不过,这些我都不熟悉,得找相关资料看看。非常感谢你的帮助。
发表于 2017-7-3 09:30:18 | 显示全部楼层
很高级,路过学习学习
发表于 2017-7-3 14:06:18 | 显示全部楼层
高级啊,学习膜拜等大神!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-23 16:13 , Processed in 0.164735 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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