#include <GuiConstantsEx.au3>
#include <WinAPIEx.au3>
#include <GDIPlusex.au3>
#include <Array.au3>
_Main()
Func _Main()
Local $hGUI, $hWnd, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $hFontCollection, $sFamilyName, $aFontFamilies, $hPointcolor, $str = ''
Local $aFont = _arraycreate('webdings', 'Symbol', 'Marlett', 'Wingdings') ;定义几个图形字符的字形
; Create GUI
$hGUI = GUICreate("GDI+", 640, 150)
$hWnd = WinGetHandle("GDI+")
GUISetState()
; Draw a string
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hFormat = _GDIPlus_StringFormatCreate()
$hFontCollection = _GDIPlus_FontCollectionCreate()
$aFontFamilies = _GDIPlus_FontCollectionGetFamilyList($hFontCollection)
For $i = 1 To 10000
$hPointcolor = _GDIPlus_BrushCreateSolid('0xFF' & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2)) ;设置干扰点颜色
_GDIPlus_GraphicsFillEllipse($hGraphic, Random(0, 640, 1), Random(0, 150, 1), 3, 3, $hPointcolor) ;随机绘制干扰点(3x3的椭圆)
If $i < 8 Then
While 1
$sFamilyName = _GDIPlus_FontFamilyGetFamilyName($aFontFamilies[Random(1, UBound($aFontFamilies) - 1, 1)]) ;随机选取字体族并获取族名(排除图形字符字形)
If _ArraySearch($aFont, $sFamilyName) Then ExitLoop
WEnd
$hFamily = _GDIPlus_FontFamilyCreate($sFamilyName) ;创建基于名字的字体族
$hBrush = _GDIPlus_BrushCreateSolid('0xFF' & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2)) ;随机设置画刷颜色
$hFont = _GDIPlus_FontCreate($hFamily, Random(24, 50, 1), Random(0, 2, 1)) ;基于字体族以随机字形及字重创建字体
$iX = 70 * ($i - 1) + Random(0, 70, 1) ;基于不同字符位置随机设置起始点的x坐标
$tLayout = _GDIPlus_RectFCreate($iX, Random(0, 50, 1)) ;创建绘制字符的矩形
$w = Random(0, 2) ;大小写开关
Select
Case $w > 1
$string = Chr(Random(65, 90, 1)) ;随机获取大写字母
Case Else
$string = Chr(Random(97, 122, 1)) ;随机获取小写字母
EndSelect
$str &= $string
$hImage = _GDIPlus_GraphicsDrawStringEx($hGraphic, $string, $hFont, $tLayout, $hFormat, $hBrush) ;绘制字符
_GDIPlus_GraphicsRotateTransform($hImage, Random(0, 180, 1), Int(Random(0, 1) + 0.5)) ;随机旋转(好像有问题,转不了)
If $i < 6 Then
$hPen = _GDIPlus_PenCreate('0xFF' & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2), Int(Random(2, 6, 1))) ;创建用于绘制干扰线的画笔(随机色及随机线宽)
_GDIPlus_GraphicsDrawLine($hGraphic, Random(0, 640, 1), Random(0, 150, 1), Random(0, 640, 1), Random(0, 150, 1), $hPen) ;按随机起始坐标及随机结束坐标绘制直线
EndIf
EndIf
Next
MsgBox(0, 0, $str)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; Clean up resources
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc ;==>_Main