GDI画画

; 自动画猫.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 := 15
; ----------------------------------------------------------------------------------------------------------------------
; Gui
Gui, +hwndhGui
Gui, Margin, 20, 20
Gui, Add, Text, w500 h200 gSubPic hwndHPIC Border vbox
Gui, Add, Button, gSubClear, 清除
Gui, Add, Button, x+10 yp gSubSave, 保存到图片
Gui, Add, Button, x+10 yp gCopyArray, 复制轨迹数组
Gui, Add, Button, x+10 yp gSaveArray, 保存轨迹数组
Gui, Add, Button, x+10 yp gReplayArray vReplayArray, 回放
Gui, Add, Checkbox, x+5 hp 0x200 vNoWait, 不记录两次落笔之间的时间
Gui, Add, Statusbar
Gui, Show, , Drawing in Control


; ----------------------------------------------------------------------------------------------------------------------
; GDI+
Token := Gdip_Startup()
Pen1 := Gdip_CreatePen(BISE, BIKUAN)
Pen2 := Gdip_CreatePen(BISE, BIKUAN / 2)
Pen_clear1 := Gdip_CreatePen(0xFFFFFFFF, BIKUAN)
Pen_clear2 := Gdip_CreatePen(0xFFFFFFFF, BIKUAN / 2)
Graphics := Gdip_GraphicsFromHWND(HPIC) ; not included in GIDP.ahk, added below
Gdip_SetSmoothingMode(Graphics, 4)
Gdip_GraphicsClear(Graphics, 0xFFFFFFFF)
BitMap := Gdip_CreateBitmap(500, 300)
BitMapGraphics := Gdip_GraphicsFromImage(BitMap)
Gdip_SetSmoothingMode(BitmapGraphics, 4)

Gdip_GraphicsClear(BitMapGraphics, 0xFFFFFFFF)
; Return

; ========================= 自动画 ... =========================
line := []
IfNotExist, 轨迹数组.txt
  Return

FileRead, line, 轨迹数组.txt ; 鼠标轨迹
line := JSON_ToObj(line)
Goto, ReplayArray
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,0,1])

   GuiControlGet, NoWait
   StartTime := !StartTime ? A_TickCount : StartTime
   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, 500, 300) ; not included in GIDP.ahk, added below
         XP := X
         YP := Y
         line.Insert( [xp,yp])

         line[ line.MaxIndex() - 1 ][3] := A_TickCount - StartTime
         StartTime := A_TickCount
      }
   }
   DllCall("USer32.dllClipCursor", "Ptr", 0)
   StartTime := NoWait ? "" : A_TickCount
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

CopyArray:
   if !line.1.1
      ToolTip, 请先画点什么...
   else
   {
      Clipboard := JSON_FromObj(line)
      ToolTip, 复制成功
   }

   Sleep, 2000
   ToolTip
Return

SaveArray:
  if !line.1.1
      ToolTip, 请先画点什么...
  else
  {
    FileDelete, 轨迹数组.txt
    FileAppend, % JSON_FromObj(line), 轨迹数组.txt
    ToolTip, 保存完毕
  }
  Sleep, 2000
  ToolTip
Return

ReplayArray:
  if !line.1.1
  {
      ToolTip, 请先画点什么...
      Sleep, 2000
      ToolTip
      Return
  }

  BtnText := (BtnText != "停止") ? "停止" : "回放"
  GuiControl,, ReplayArray, % BtnText

  if (BtnText = "回放")
    ToolTip, 停止中...
  SetTimer, ReplayArray_Timer, -1
Return

ReplayArray_Timer:
  if (BtnText = "回放")
    Return

  Gdip_GraphicsClear(Graphics, 0xFFFFFFFF)
  Gdip_GraphicsClear(BitMapGraphics, 0xFFFFFFFF)

  newLine := [] ; 如果中断了回放,则轨迹替换为这个

  for i, n in line
  {
    newLine.Insert(n)

     x := n.1, y := n.2

     if n.4
     {
        XP := X, YP := Y
        Gdip_DrawEllipse(BitmapGraphics, Pen2, XP - (BIKUAN / 4), YP - (BIKUAN  / 4), BIKUAN / 2, BIKUAN / 2)
        Sleep, % n.3
        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, 500, 300) ; not included in GIDP.ahk, added below
     , XP := X, YP := Y
     Sleep, % n.3

     if (BtnText = "回放")
     {
      line := newLine, newLine := ""
      ToolTip, 已停止
      Sleep, 2000
      ToolTip
      Return
     }
  }

  GuiControl,, ReplayArray, % BtnText := "回放"
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
}

给TA捐赠
共{{data.count}}人
人已捐赠
其他案例

GDIP时钟

2020-3-29 2:16:22

其他案例

Habit-1542带调试功能

2020-3-30 5:47:23

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索