; 自动画猫.ahk ; 脚本修改自 http://ahkscript.org/boards/viewtopic.php?f=5&t=1257#p8501 ; 感谢 汐潮、just me... #NoEnv #Persistent #SingleInstance force #Include#Include #Include SetBatchLines, -1 ; ---------------------------------------------------------------------------------------------------------------------- ; Settings global chicun:=300 BISE := 0xFFFF8000 BIKUAN := 8 ; ---------------------------------------------------------------------------------------------------------------------- ; Gui Gui, +hwndhGui Gui, Margin, 20, 20 Gui, Add, Text, w300 h300 gSubPic hwndHPIC Border vbox Gui, Add, Button, gSubClear, Clear Gui, Add, Button, x+20 yp gSubSave, Save Gui, Add, Button, x+20 yp gCopyLine, 复制轨迹数组 Gui, Add, Statusbar Gui, Show, , Drawing in Control ; ---------------------------------------------------------------------------------------------------------------------- ; GDI+ Token := Gdip_Startup() Pen1 := Gdip_CreatePen(BISE, BIKUAN) Pen2 := Gdip_CreatePen(BISE, BIKUAN / 2) Graphics := Gdip_GraphicsFromHWND(HPIC) ; not included in GIDP.ahk, added below Gdip_SetSmoothingMode(Graphics, 4) Gdip_GraphicsClear(Graphics, 0xFFFFFFFF) BitMap := Gdip_CreateBitmap(300, 300) BitMapGraphics := Gdip_GraphicsFromImage(BitMap) Gdip_SetSmoothingMode(BitmapGraphics, 4) Gdip_GraphicsClear(BitMapGraphics, 0xFFFFFFFF) ; ========================= 自动画 ... ========================= IfNotExist, 猫.txt Return FileRead, p, 猫.txt ; 鼠标轨迹 p := JSON_ToObj(p) for i, n in P { x := n.1, y := n.2 if n.3 { XP := X, YP := Y Gdip_DrawEllipse(BitmapGraphics, Pen2, XP - (BIKUAN / 4), YP - (BIKUAN / 4), BIKUAN / 2, BIKUAN / 2) Continue } Gdip_DrawLine(BitMapGraphics, Pen1, XP, YP, X, Y) , Gdip_DrawEllipse(BitMapGraphics, Pen2, X - (BIKUAN / 4), Y - (BIKUAN / 4), BIKUAN / 2, BIKUAN / 2) , Gdip_DrawImageRect(Graphics, Bitmap, 0, 0, 300, 300) ; not included in GIDP.ahk, added below , XP := X, YP := Y } line := p Return ; ====================================================================================================================== GuiClose: ExitApp ; ====================================================================================================================== ; Drawing SubPic: VarSetCapacity(RECT, 16, 0) DllCall("User32.dllGetWindowRect", "Ptr", HPIC, "Ptr", &RECT) DllCall("USer32.dllClipCursor", "Ptr", &RECT) GetRelativeCursorPos(HPIC, XP, YP) Gdip_DrawEllipse(BitmapGraphics, Pen2, XP - (BIKUAN / 4), YP - (BIKUAN / 4), BIKUAN / 2, BIKUAN / 2) line.Insert( [xp,yp,1]) While GetKeyState("LButton", "P") { GetRelativeCursorPos(HPIC, X, Y) If (X != XP) || (Y != YP) { Gdip_DrawLine(BitMapGraphics, Pen1, XP, YP, X, Y) Gdip_DrawEllipse(BitMapGraphics, Pen2, X - (BIKUAN / 4), Y - (BIKUAN / 4), BIKUAN / 2, BIKUAN / 2) Gdip_DrawImageRect(Graphics, Bitmap, 0, 0, 300, 300) ; not included in GIDP.ahk, added below XP := X YP := Y line.Insert( [xp,yp]) } } DllCall("USer32.dllClipCursor", "Ptr", 0) Return ; ====================================================================================================================== ; Clear the control SubClear: Gdip_GraphicsClear(Graphics, 0xFFFFFFFF) Gdip_GraphicsClear(BitMapGraphics, 0xFFFFFFFF) line := [] Return ; ====================================================================================================================== ; Save the image SubSave: FileSelectFile, ImagePath, s24, %A_ScriptDir%Pic.jpg, Save File?, Image (*.bmp; *.jpg; *.png) If (ImagePath) { If !Gdip_SaveBitmapToFile(Bitmap, ImagePath, 100) SB_SetText(" Image saved as " . Path) Else SB_SetText(" Couldn't save image!") } Return CopyLine: if !line.1.1 ToolTip, 请先画点什么... else { Clipboard := JSON_FromObj(line) ToolTip, 复制成功 } Sleep, 2000 ToolTip Return ; ====================================================================================================================== ; Free GDI+ resources AppExit: Gdip_DeletePen(Pen1) Gdip_DeletePen(Pen2) Gdip_DisposeImage(BitMap) Gdip_DeleteGraphics(BitmapGraphics) Gdip_DeleteGraphics(Graphics) Gdip_ShutDown(Token) ExitApp ; ====================================================================================================================== ; Retrieves a GDI+ graphics object for this HWND Gdip_GraphicsFromHWND(HWND) { DllCall("Gdiplus.dllGdipCreateFromHWND", "Ptr", HWND, "PtrP", Graphics) Return Graphics } ; ====================================================================================================================== ; Draws the image using the passed position and dimensions Gdip_DrawImageRect(Graphics, Bitmap, X := "", Y := "", W := "", H := "") { If (X = "") X := 0 If (Y = "") Y := 0 If (W = "") W := Gdip_GetImageWidth(Bitmap) If (H = "") W := Gdip_GetImageHeight(Bitmap) Return DllCall("Gdiplus.dllGdipDrawImageRect", "Ptr", Graphics, "Ptr", Bitmap, "Float", X, "Float", Y, "Float", W, "Float", H) } ; ====================================================================================================================== ; Retrieves the cursor position relative to this HWND GetRelativeCursorPos(HWND, ByRef X, ByRef Y) { VarSetCapacity(POINT, 8, 0) DllCall("User32.dllGetCursorPos", "Ptr", &POINT) DllCall("User32.dllScreenToClient", "Ptr", HWND, "Ptr", &POINT) X := NumGet(POINT, 0, "Int") Y := NumGet(POINT, 4, "Int") Return True } Proportion(a){ ; Reduced to the specified range. for i,n in a if A_Index = 1 x1:=x2:=n.1,y1:=y2:=n.2 else ((n.1 > x1) ? (x1:=n.1) : (n.1 y1) ? (y1:=n.2) : (n.2 (y3:=y1 - y2)) ? x3 : y3) / ((chicun/7)*6), y4:=x4:=chicun/14 ,((x3>y3) ? y4+=((chicun-(y3/j))/3) : x4+=((chicun-(x3/j))/3)) ,p:=[] for i,n in a p.Insert([Ceil(((n.1-x2)//j) + x4),Ceil(((n.2-y2)//j) + y4)]) Return p }