Guest User

Untitled

a guest
Feb 9th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 94.89 KB | None | 0 0
  1. ;Made by Bugz000, set DIR to a directory you wish any non-icons to be moved to
  2. ;then run the program for instant clear desktop :)
  3. Dir := "K:\Stuff"
  4.  
  5. #singleinstance, force
  6. setworkingdir %A_Desktop%
  7. CircleProgress := new CircleProgressClass({y: 500, TextStyle: "Bold", BarThickness: 10, BarDiameter: 140})
  8. CircleProgress.Update(0, setting environment)
  9. WinGet, _id, ID, A
  10. IfNOTExist, %Dir%
  11. FileCreateDir, %Dir%
  12. if (ErrorLevel)
  13. loop 3
  14. if (A_index = 1)
  15. loop 255
  16. CircleProgress.Update(100, "Target Dir is not valid :(")
  17. else if (A_index = 2)
  18. loop 255
  19. CircleProgress.Update(100, "Target Dir is not valid :(", (255 - A_index))
  20. else if (A_index = 3)
  21. exitapp
  22. Loop, Files, *, R
  23. if (A_LoopFileExt != "lnk")
  24. if (A_LoopFileExt != "url")
  25. {
  26.  
  27. Count+=1
  28. File%Count% := A_LoopFileFullPath
  29. FileGetSize, FileSize, %A_LoopFileFullPath%, K
  30. File%Count%size := Filesize
  31. CircleProgress.Update(0, "Gathering Information`r`n" Count)
  32. }
  33. Loop, %count%
  34. {
  35. CircleProgress.Update(0, "Checking destinations`r`n" A_Index)
  36. S := File%A_Index%
  37. IfNOTExist, %Dir%\%S%
  38. File%A_Index%Des = %Dir%\%S%
  39. else
  40. {
  41. t := A_Index
  42. i = 1
  43. loop
  44. IfNOTExist, %Dir%\%i% %S%
  45. {
  46. File%t%Des = %Dir%\%i% %S%
  47. break
  48. }
  49. else
  50. i++
  51. }
  52. }
  53. loop %count%
  54. {
  55. if !(InStr(FileExist(SubStr(File%A_Index%Des, 1, InStr(SubStr(File%A_Index%Des,1,-1), "\", 0, 0)-1)), "D"))
  56. {
  57. CircleProgress.Update(((A_index * 100) / Count), "Creating required`r`ndirectories" )
  58. FileCreateDir, % SubStr(File%A_Index%Des, 1, InStr(SubStr(File%A_Index%Des,1,-1), "\", 0, 0)-1)
  59. }
  60. }
  61.  
  62.  
  63. loop %count%
  64. Move(a_index, file%A_index%, File%A_Index%Des)
  65.  
  66. loop %count%
  67. {
  68. CircleProgress.Update(((A_index * 100) / Count), "Cleaning up`r`nold directories" )
  69. if (InStr(FileExist(SubStr(File%A_Index%, 1, InStr(SubStr(File%A_Index%,1,-1), "\", 0, 0)-1)), "D"))
  70. FileRemoveDir % SubStr(File%A_Index%, 1, InStr(SubStr(File%A_Index%,1,-1), "\", 0, 0)-1), 1
  71. }
  72. CircleProgress.Update(100, "Clearing Pre-existing empty folders...")
  73. Loop, *, 2, 1
  74. FileRemoveDir, %A_LoopFileLongPath%, 1
  75.  
  76. if (Count)
  77. loop 255
  78. CircleProgress.Update(100, Count "`r`n" Filesize " kb`r`n" T " kb", (255 - A_index))
  79. else
  80. loop 3
  81. if (A_index = 1)
  82. loop 255
  83. CircleProgress.Update(100, "No Files to move :)")
  84. else if (A_index = 2)
  85. loop 255
  86. CircleProgress.Update(100, "No Files to move :)", (255 - A_index))
  87. else if (A_index = 3)
  88. exitapp
  89.  
  90. sleep 100
  91. ControlSend,, {F5}, ahk_class Progman
  92. exitapp
  93.  
  94. Move(index, Src, Des)
  95. {
  96. global
  97. Filesize := File%index%Size
  98. t += filesize
  99. CircleProgress.Update(((index * 100) / Count), index "`r`n" FileSize "kb`r`n" T "kb" )
  100. a := index
  101. rar := ((count / 100) * index), index "`r`n" FileSize "`r`n" T
  102. FileMove, %src%, %des%
  103.  
  104.  
  105. }
  106.  
  107.  
  108. class CircleProgressClass { ; http://ahkscript.org/boards/viewtopic.php?p=41794#p41794
  109. ; Credits: Bruttosozialprodukt, Learning one. This code is public domain.
  110. static Version := 1.04
  111. __New(Options="") {
  112. this.BarDiameter := (Options.HasKey("BarDiameter") = 1) ? Options.BarDiameter : 110
  113. this.BarThickness := (Options.HasKey("BarThickness") = 1) ? Options.BarThickness : 16
  114. this.BarColor := (Options.HasKey("BarColor") = 1) ? Options.BarColor : "dd228822"
  115. this.BackgroundColor := (Options.HasKey("BackgroundColor") = 1) ? Options.BackgroundColor : "ffffffff"
  116. this.TextColor := (Options.HasKey("TextColor") = 1) ? Options.TextColor : "ee000000"
  117. this.TextSize := (Options.HasKey("TextSize") = 1) ? Options.TextSize : 11
  118. this.TextRendering := (Options.HasKey("TextRendering") = 1) ? Options.TextRendering : 5
  119. this.TextFont := (Options.HasKey("TextFont") = 1) ? Options.TextFont : "Arial"
  120. this.TextStyle := (Options.HasKey("TextStyle") = 1) ? Options.TextStyle : "" ; you can use for example "Bold Italic"
  121. this.X := (Options.HasKey("X") = 1) ? Options.X : Round(A_ScreenWidth/2-this.BarDiameter/2-this.BarThickness) ; centered is defualt
  122. this.Y := (Options.HasKey("Y") = 1) ? Options.Y : Round(A_ScreenHeight/2-this.BarDiameter/2-this.BarThickness) ; centered is defualt
  123. this.W := this.BarDiameter+this.BarThickness*2+2 ; it's good to add 2 extra pixels
  124. this.UseClickThrough := (Options.HasKey("UseClickThrough") = 1) ? Options.UseClickThrough : 1 ; 1 = use it, 0 = don't use it
  125.  
  126. Gui, New, +Hwndhwnd
  127. Gui %hwnd%: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  128. Gui %hwnd%: Show, NA
  129. if (this.UseClickThrough = 1)
  130. WinSet, ExStyle, +0x20, % "ahk_id " hwnd ; click through style
  131.  
  132. hbm := CreateDIBSection(this.W, this.W), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  133. pPen:=Gdip_CreatePen("0x" this.BarColor, this.BarThickness)
  134. if (pPen = 0) { ; GDI+ is not started up - start it up now and shut it down in __Delete() automatically.
  135. pToken := Gdip_Startup()
  136. pPen:=Gdip_CreatePen("0x" this.BarColor, this.BarThickness) ; call it again (with GDI+ started up now)
  137. }
  138. G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4)
  139.  
  140. if (this.BackgroundColor > 0)
  141. pBrush:=Gdip_BrushCreateSolid("0x" this.BackgroundColor)
  142.  
  143. this.hwnd := hwnd, this.hdc := hdc, this.obm := obm, this.hbm := hbm, this.pPen := pPen, this.pBrush := pBrush, this.G := G, this.pToken := pToken
  144. }
  145. Update(Percent=0, Text="", Alpha=255) {
  146. Gdip_GraphicsClear(this.G)
  147. if (this.BackgroundColor > 0)
  148. Gdip_FillEllipse(this.G, this.pBrush, this.BarThickness+1, this.BarThickness+1, this.BarDiameter,this.BarDiameter)
  149. if (Percent>0)
  150. Gdip_DrawArc(this.G, this.pPen, Round(this.BarThickness/2)+1, Round(this.BarThickness/2)+1, this.BarDiameter+this.BarThickness, this.BarDiameter+this.BarThickness, 270, Round(360/100*percent))
  151. if (Text!="") {
  152. Options := Trim("x1 y1 w" this.W-2 " h" this.W-2 " Center Vcenter r" this.TextRendering " s" this.TextSize " c" this.TextColor A_Space this.TextStyle)
  153. Gdip_TextToGraphics(this.G, Text, Options, this.TextFont)
  154. }
  155. ;pControlPen:=Gdip_CreatePen("0xffff0000", 1), Gdip_DrawRectangle(this.G, pControlPen, 1, 1, this.W-2,this.W-2), Gdip_DeletePen(pControlPen)
  156. UpdateLayeredWindow(this.hwnd, this.hdc, this.X, this.Y, this.W, this.W, Alpha)
  157. }
  158. Clear() { ; Just clears the graphics and updates layered window. Doesn't destroy object nor clear resources.
  159. Gdip_GraphicsClear(this.G)
  160. UpdateLayeredWindow(this.hwnd, this.hdc, this.X, this.Y, this.W, this.W)
  161. }
  162. __Delete() {
  163. Gdip_DeletePen(this.pPen)
  164. if (this.BackgroundColor > 0)
  165. Gdip_DeleteBrush(this.pBrush)
  166. Gdip_DeleteGraphics(this.G)
  167. SelectObject(this.hdc, this.obm)
  168. DeleteObject(this.hbm)
  169. DeleteDC(this.hdc)
  170. if (this.pToken != "") ; GDI+ was obviously automatically started up in __New(), and therefore shut it down automatically now
  171. Gdip_Shutdown(this.pToken)
  172. hwnd := this.hwnd
  173. Gui %hwnd%: Destroy
  174. }
  175. FadeOut(end = 0, speed = 10) {
  176. Window := "ahk_id " this.hwnd
  177. WinGet, currentTrans, Transparent, %window% ; Set varialbe "currentTrans" to whatever the desired windows transparacy is
  178. If (currentTrans == "") ; Check if the window is in "Off" mode
  179. {
  180. WinSet, Trans, 255, %window% ; Sets the window to max transpacity so that it may be changed
  181. WinGet, currentTrans, Transparent, %window% ; Reset varialbe "currentTrans"
  182. }
  183. While, (currentTrans > end)
  184. {
  185. Sleep, % speed / 2 ; This is just for a more smooth effect, can be buggy
  186. Trans := currentTrans - speed ; Sets the transpacity, I'm pretty sure this is where I messed up
  187. WinSet, Trans, %Trans%, %window%
  188. WinGet, currentTrans, Transparent, %window% ; Resets the variable "currentTrans" to what the windows new transpacity is so the While loop knows when to end
  189. }
  190. }
  191.  
  192. }
  193.  
  194. ;GDIP Lib
  195. ; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11
  196. ;
  197. ;#####################################################################################
  198. ;#####################################################################################
  199. ; STATUS ENUMERATION
  200. ; Return values for functions specified to have status enumerated return type
  201. ;#####################################################################################
  202. ;
  203. ; Ok = = 0
  204. ; GenericError = 1
  205. ; InvalidParameter = 2
  206. ; OutOfMemory = 3
  207. ; ObjectBusy = 4
  208. ; InsufficientBuffer = 5
  209. ; NotImplemented = 6
  210. ; Win32Error = 7
  211. ; WrongState = 8
  212. ; Aborted = 9
  213. ; FileNotFound = 10
  214. ; ValueOverflow = 11
  215. ; AccessDenied = 12
  216. ; UnknownImageFormat = 13
  217. ; FontFamilyNotFound = 14
  218. ; FontStyleNotFound = 15
  219. ; NotTrueTypeFont = 16
  220. ; UnsupportedGdiplusVersion = 17
  221. ; GdiplusNotInitialized = 18
  222. ; PropertyNotFound = 19
  223. ; PropertyNotSupported = 20
  224. ; ProfileNotFound = 21
  225. ;
  226. ;#####################################################################################
  227. ;#####################################################################################
  228. ; FUNCTIONS
  229. ;#####################################################################################
  230. ;
  231. ; UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  232. ; BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  233. ; StretchBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, sw, sh, Raster="")
  234. ; SetImage(hwnd, hBitmap)
  235. ; Gdip_BitmapFromScreen(Screen=0, Raster="")
  236. ; CreateRectF(ByRef RectF, x, y, w, h)
  237. ; CreateSizeF(ByRef SizeF, w, h)
  238. ; CreateDIBSection
  239. ;
  240. ;#####################################################################################
  241.  
  242. ; Function: UpdateLayeredWindow
  243. ; Description: Updates a layered window with the handle to the DC of a gdi bitmap
  244. ;
  245. ; hwnd Handle of the layered window to update
  246. ; hdc Handle to the DC of the GDI bitmap to update the window with
  247. ; Layeredx x position to place the window
  248. ; Layeredy y position to place the window
  249. ; Layeredw Width of the window
  250. ; Layeredh Height of the window
  251. ; Alpha Default = 255 : The transparency (0-255) to set the window transparency
  252. ;
  253. ; return If the function succeeds, the return value is nonzero
  254. ;
  255. ; notes If x or y omitted, then layered window will use its current coordinates
  256. ; If w or h omitted then current width and height will be used
  257.  
  258. UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  259. {
  260. if ((x != "") && (y != ""))
  261. VarSetCapacity(pt, 8), NumPut(x, pt, 0), NumPut(y, pt, 4)
  262.  
  263. if (w = "") ||(h = "")
  264. WinGetPos,,, w, h, ahk_id %hwnd%
  265.  
  266. return DllCall("UpdateLayeredWindow", "uint", hwnd, "uint", 0, "uint", ((x = "") && (y = "")) ? 0 : &pt
  267. , "int64*", w|h<<32, "uint", hdc, "int64*", 0, "uint", 0, "uint*", Alpha<<16|1<<24, "uint", 2)
  268. }
  269.  
  270. ;#####################################################################################
  271.  
  272. ; Function BitBlt
  273. ; Description The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle
  274. ; of pixels from the specified source device context into a destination device context.
  275. ;
  276. ; dDC handle to destination DC
  277. ; dx x-coord of destination upper-left corner
  278. ; dy y-coord of destination upper-left corner
  279. ; dw width of the area to copy
  280. ; dh height of the area to copy
  281. ; sDC handle to source DC
  282. ; sx x-coordinate of source upper-left corner
  283. ; sy y-coordinate of source upper-left corner
  284. ; Raster raster operation code
  285. ;
  286. ; return If the function succeeds, the return value is nonzero
  287. ;
  288. ; notes If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle
  289. ;
  290. ; BLACKNESS = 0x00000042
  291. ; NOTSRCERASE = 0x001100A6
  292. ; NOTSRCCOPY = 0x00330008
  293. ; SRCERASE = 0x00440328
  294. ; DSTINVERT = 0x00550009
  295. ; PATINVERT = 0x005A0049
  296. ; SRCINVERT = 0x00660046
  297. ; SRCAND = 0x008800C6
  298. ; MERGEPAINT = 0x00BB0226
  299. ; MERGECOPY = 0x00C000CA
  300. ; SRCCOPY = 0x00CC0020
  301. ; SRCPAINT = 0x00EE0086
  302. ; PATCOPY = 0x00F00021
  303. ; PATPAINT = 0x00FB0A09
  304. ; WHITENESS = 0x00FF0062
  305. ; CAPTUREBLT = 0x40000000
  306. ; NOMIRRORBITMAP = 0x80000000
  307.  
  308. BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  309. {
  310. return DllCall("gdi32\BitBlt", "uint", dDC, "int", dx, "int", dy, "int", dw, "int", dh
  311. , "uint", sDC, "int", sx, "int", sy, "uint", Raster ? Raster : 0x00CC0020)
  312. }
  313.  
  314. ;#####################################################################################
  315.  
  316. ; Function StretchBlt
  317. ; Description The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle,
  318. ; stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
  319. ; The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.
  320. ;
  321. ; ddc handle to destination DC
  322. ; dx x-coord of destination upper-left corner
  323. ; dy y-coord of destination upper-left corner
  324. ; dw width of destination rectangle
  325. ; dh height of destination rectangle
  326. ; sdc handle to source DC
  327. ; sx x-coordinate of source upper-left corner
  328. ; sy y-coordinate of source upper-left corner
  329. ; sw width of source rectangle
  330. ; sh height of source rectangle
  331. ; Raster raster operation code
  332. ;
  333. ; return If the function succeeds, the return value is nonzero
  334. ;
  335. ; notes If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt
  336.  
  337. StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="")
  338. {
  339. return DllCall("gdi32\StretchBlt", "uint", ddc, "int", dx, "int", dy, "int", dw, "int", dh
  340. , "uint", sdc, "int", sx, "int", sy, "int", sw, "int", sh, "uint", Raster ? Raster : 0x00CC0020)
  341. }
  342.  
  343. ;#####################################################################################
  344.  
  345. ; Function SetStretchBltMode
  346. ; Description The SetStretchBltMode function sets the bitmap stretching mode in the specified device context
  347. ;
  348. ; hdc handle to the DC
  349. ; iStretchMode The stretching mode, describing how the target will be stretched
  350. ;
  351. ; return If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0
  352. ;
  353. ; STRETCH_ANDSCANS = 0x01
  354. ; STRETCH_ORSCANS = 0x02
  355. ; STRETCH_DELETESCANS = 0x03
  356. ; STRETCH_HALFTONE = 0x04
  357.  
  358. SetStretchBltMode(hdc, iStretchMode=4)
  359. {
  360. return DllCall("gdi32\SetStretchBltMode", "uint", hdc, "int", iStretchMode)
  361. }
  362.  
  363. ;#####################################################################################
  364.  
  365. ; Function SetImage
  366. ; Description Associates a new image with a static control
  367. ;
  368. ; hwnd handle of the control to update
  369. ; hBitmap a gdi bitmap to associate the static control with
  370. ;
  371. ; return If the function succeeds, the return value is nonzero
  372.  
  373. SetImage(hwnd, hBitmap)
  374. {
  375. SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
  376. E := ErrorLevel
  377. DeleteObject(E)
  378. return E
  379. }
  380.  
  381. ;#####################################################################################
  382.  
  383. ; Function SetSysColorToControl
  384. ; Description Sets a solid colour to a control
  385. ;
  386. ; hwnd handle of the control to update
  387. ; SysColor A system colour to set to the control
  388. ;
  389. ; return If the function succeeds, the return value is zero
  390. ;
  391. ; notes A control must have the 0xE style set to it so it is recognised as a bitmap
  392. ; By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control
  393. ;
  394. ; COLOR_3DDKSHADOW = 21
  395. ; COLOR_3DFACE = 15
  396. ; COLOR_3DHIGHLIGHT = 20
  397. ; COLOR_3DHILIGHT = 20
  398. ; COLOR_3DLIGHT = 22
  399. ; COLOR_3DSHADOW = 16
  400. ; COLOR_ACTIVEBORDER = 10
  401. ; COLOR_ACTIVECAPTION = 2
  402. ; COLOR_APPWORKSPACE = 12
  403. ; COLOR_BACKGROUND = 1
  404. ; COLOR_BTNFACE = 15
  405. ; COLOR_BTNHIGHLIGHT = 20
  406. ; COLOR_BTNHILIGHT = 20
  407. ; COLOR_BTNSHADOW = 16
  408. ; COLOR_BTNTEXT = 18
  409. ; COLOR_CAPTIONTEXT = 9
  410. ; COLOR_DESKTOP = 1
  411. ; COLOR_GRADIENTACTIVECAPTION = 27
  412. ; COLOR_GRADIENTINACTIVECAPTION = 28
  413. ; COLOR_GRAYTEXT = 17
  414. ; COLOR_HIGHLIGHT = 13
  415. ; COLOR_HIGHLIGHTTEXT = 14
  416. ; COLOR_HOTLIGHT = 26
  417. ; COLOR_INACTIVEBORDER = 11
  418. ; COLOR_INACTIVECAPTION = 3
  419. ; COLOR_INACTIVECAPTIONTEXT = 19
  420. ; COLOR_INFOBK = 24
  421. ; COLOR_INFOTEXT = 23
  422. ; COLOR_MENU = 4
  423. ; COLOR_MENUHILIGHT = 29
  424. ; COLOR_MENUBAR = 30
  425. ; COLOR_MENUTEXT = 7
  426. ; COLOR_SCROLLBAR = 0
  427. ; COLOR_WINDOW = 5
  428. ; COLOR_WINDOWFRAME = 6
  429. ; COLOR_WINDOWTEXT = 8
  430.  
  431. SetSysColorToControl(hwnd, SysColor=15)
  432. {
  433. WinGetPos,,, w, h, ahk_id %hwnd%
  434. bc := DllCall("GetSysColor", "Int", SysColor)
  435. pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
  436. pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap)
  437. Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
  438. hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  439. SetImage(hwnd, hBitmap)
  440. Gdip_DeleteBrush(pBrushClear)
  441. Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
  442. return 0
  443. }
  444.  
  445. ;#####################################################################################
  446.  
  447. ; Function Gdip_BitmapFromScreen
  448. ; Description Gets a gdi+ bitmap from the screen
  449. ;
  450. ; Screen 0 = All screens
  451. ; Any numerical value = Just that screen
  452. ; x|y|w|h = Take specific coordinates with a width and height
  453. ; Raster raster operation code
  454. ;
  455. ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap
  456. ; -1: one or more of x,y,w,h not passed properly
  457. ;
  458. ; notes If no raster operation is specified, then SRCCOPY is used to the returned bitmap
  459.  
  460. Gdip_BitmapFromScreen(Screen=0, Raster="")
  461. {
  462. if (Screen = 0)
  463. {
  464. Sysget, x, 76
  465. Sysget, y, 77
  466. Sysget, w, 78
  467. Sysget, h, 79
  468. }
  469. else if (SubStr(Screen, 1, 5) = "hwnd:")
  470. {
  471. Screen := SubStr(Screen, 6)
  472. if !WinExist( "ahk_id " Screen)
  473. return -2
  474. WinGetPos,,, w, h, ahk_id %Screen%
  475. x := y := 0
  476. hhdc := GetDCEx(Screen, 3)
  477. }
  478. else if (Screen&1 != "")
  479. {
  480. Sysget, M, Monitor, %Screen%
  481. x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
  482. }
  483. else
  484. {
  485. StringSplit, S, Screen, |
  486. x := S1, y := S2, w := S3, h := S4
  487. }
  488.  
  489. if (x = "") || (y = "") || (w = "") || (h = "")
  490. return -1
  491.  
  492. chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
  493. BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
  494. ReleaseDC(hhdc)
  495.  
  496. pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  497. SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
  498. return pBitmap
  499. }
  500.  
  501. ;#####################################################################################
  502.  
  503. ; Function Gdip_BitmapFromHWND
  504. ; Description Uses PrintWindow to get a handle to the specified window and return a bitmap from it
  505. ;
  506. ; hwnd handle to the window to get a bitmap from
  507. ;
  508. ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap
  509. ;
  510. ; notes Window must not be not minimised in order to get a handle to it's client area
  511.  
  512. Gdip_BitmapFromHWND(hwnd)
  513. {
  514. WinGetPos,,, Width, Height, ahk_id %hwnd%
  515. hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  516. PrintWindow(hwnd, hdc)
  517. pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  518. SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  519. return pBitmap
  520. }
  521.  
  522. ;#####################################################################################
  523.  
  524. ; Function CreateRectF
  525. ; Description Creates a RectF object, containing a the coordinates and dimensions of a rectangle
  526. ;
  527. ; RectF Name to call the RectF object
  528. ; x x-coordinate of the upper left corner of the rectangle
  529. ; y y-coordinate of the upper left corner of the rectangle
  530. ; w Width of the rectangle
  531. ; h Height of the rectangle
  532. ;
  533. ; return No return value
  534.  
  535. CreateRectF(ByRef RectF, x, y, w, h)
  536. {
  537. VarSetCapacity(RectF, 16)
  538. NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
  539. }
  540.  
  541. ;#####################################################################################
  542.  
  543. ; Function CreateRect
  544. ; Description Creates a Rect object, containing a the coordinates and dimensions of a rectangle
  545. ;
  546. ; RectF Name to call the RectF object
  547. ; x x-coordinate of the upper left corner of the rectangle
  548. ; y y-coordinate of the upper left corner of the rectangle
  549. ; w Width of the rectangle
  550. ; h Height of the rectangle
  551. ;
  552. ; return No return value
  553.  
  554. CreateRect(ByRef Rect, x, y, w, h)
  555. {
  556. VarSetCapacity(Rect, 16)
  557. NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint")
  558. }
  559. ;#####################################################################################
  560.  
  561. ; Function CreateSizeF
  562. ; Description Creates a SizeF object, containing an 2 values
  563. ;
  564. ; SizeF Name to call the SizeF object
  565. ; w w-value for the SizeF object
  566. ; h h-value for the SizeF object
  567. ;
  568. ; return No Return value
  569.  
  570. CreateSizeF(ByRef SizeF, w, h)
  571. {
  572. VarSetCapacity(SizeF, 8)
  573. NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")
  574. }
  575. ;#####################################################################################
  576.  
  577. ; Function CreatePointF
  578. ; Description Creates a SizeF object, containing an 2 values
  579. ;
  580. ; SizeF Name to call the SizeF object
  581. ; w w-value for the SizeF object
  582. ; h h-value for the SizeF object
  583. ;
  584. ; return No Return value
  585.  
  586. CreatePointF(ByRef PointF, x, y)
  587. {
  588. VarSetCapacity(PointF, 8)
  589. NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")
  590. }
  591. ;#####################################################################################
  592.  
  593. ; Function CreateDIBSection
  594. ; Description The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly
  595. ;
  596. ; w width of the bitmap to create
  597. ; h height of the bitmap to create
  598. ; hdc a handle to the device context to use the palette from
  599. ; bpp bits per pixel (32 = ARGB)
  600. ; ppvBits A pointer to a variable that receives a pointer to the location of the DIB bit values
  601. ;
  602. ; return returns a DIB. A gdi bitmap
  603. ;
  604. ; notes ppvBits will receive the location of the pixels in the DIB
  605.  
  606. CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
  607. {
  608. hdc2 := hdc ? hdc : GetDC()
  609. VarSetCapacity(bi, 40, 0)
  610. NumPut(w, bi, 4), NumPut(h, bi, 8), NumPut(40, bi, 0), NumPut(1, bi, 12, "ushort"), NumPut(0, bi, 16), NumPut(bpp, bi, 14, "ushort")
  611. hbm := DllCall("CreateDIBSection", "uint" , hdc2, "uint" , &bi, "uint" , 0, "uint*", ppvBits, "uint" , 0, "uint" , 0)
  612.  
  613. if !hdc
  614. ReleaseDC(hdc2)
  615. return hbm
  616. }
  617.  
  618. ;#####################################################################################
  619.  
  620. ; Function PrintWindow
  621. ; Description The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC
  622. ;
  623. ; hwnd A handle to the window that will be copied
  624. ; hdc A handle to the device context
  625. ; Flags Drawing options
  626. ;
  627. ; return If the function succeeds, it returns a nonzero value
  628. ;
  629. ; PW_CLIENTONLY = 1
  630.  
  631. PrintWindow(hwnd, hdc, Flags=0)
  632. {
  633. return DllCall("PrintWindow", "uint", hwnd, "uint", hdc, "uint", Flags)
  634. }
  635.  
  636. ;#####################################################################################
  637.  
  638. ; Function DestroyIcon
  639. ; Description Destroys an icon and frees any memory the icon occupied
  640. ;
  641. ; hIcon Handle to the icon to be destroyed. The icon must not be in use
  642. ;
  643. ; return If the function succeeds, the return value is nonzero
  644.  
  645. DestroyIcon(hIcon)
  646. {
  647. return DllCall("DestroyIcon", "uint", hIcon)
  648. }
  649.  
  650. ;#####################################################################################
  651.  
  652. PaintDesktop(hdc)
  653. {
  654. return DllCall("PaintDesktop", "uint", hdc)
  655. }
  656.  
  657. ;#####################################################################################
  658.  
  659. CreateCompatibleBitmap(hdc, w, h)
  660. {
  661. return DllCall("gdi32\CreateCompatibleBitmap", "uint", hdc, "int", w, "int", h)
  662. }
  663.  
  664. ;#####################################################################################
  665.  
  666. ; Function CreateCompatibleDC
  667. ; Description This function creates a memory device context (DC) compatible with the specified device
  668. ;
  669. ; hdc Handle to an existing device context
  670. ;
  671. ; return returns the handle to a device context or 0 on failure
  672. ;
  673. ; notes If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen
  674.  
  675. CreateCompatibleDC(hdc=0)
  676. {
  677. return DllCall("CreateCompatibleDC", "uint", hdc)
  678. }
  679.  
  680. ;#####################################################################################
  681.  
  682. ; Function SelectObject
  683. ; Description The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type
  684. ;
  685. ; hdc Handle to a DC
  686. ; hgdiobj A handle to the object to be selected into the DC
  687. ;
  688. ; return If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced
  689. ;
  690. ; notes The specified object must have been created by using one of the following functions
  691. ; Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time)
  692. ; Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
  693. ; Font - CreateFont, CreateFontIndirect
  694. ; Pen - CreatePen, CreatePenIndirect
  695. ; Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect
  696. ;
  697. ; notes If the selected object is a region and the function succeeds, the return value is one of the following value
  698. ;
  699. ; SIMPLEREGION = 2 Region consists of a single rectangle
  700. ; COMPLEXREGION = 3 Region consists of more than one rectangle
  701. ; NULLREGION = 1 Region is empty
  702.  
  703. SelectObject(hdc, hgdiobj)
  704. {
  705. return DllCall("SelectObject", "uint", hdc, "uint", hgdiobj)
  706. }
  707.  
  708. ;#####################################################################################
  709.  
  710. ; Function DeleteObject
  711. ; Description This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object
  712. ; After the object is deleted, the specified handle is no longer valid
  713. ;
  714. ; hObject Handle to a logical pen, brush, font, bitmap, region, or palette to delete
  715. ;
  716. ; return Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context
  717.  
  718. DeleteObject(hObject)
  719. {
  720. return DllCall("DeleteObject", "uint", hObject)
  721. }
  722.  
  723. ;#####################################################################################
  724.  
  725. ; Function GetDC
  726. ; Description This function retrieves a handle to a display device context (DC) for the client area of the specified window.
  727. ; The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window.
  728. ;
  729. ; hwnd Handle to the window whose device context is to be retrieved. If this value is NULL, GetDC retrieves the device context for the entire screen
  730. ;
  731. ; return The handle the device context for the specified window's client area indicates success. NULL indicates failure
  732.  
  733. GetDC(hwnd=0)
  734. {
  735. return DllCall("GetDC", "uint", hwnd)
  736. }
  737.  
  738. ;#####################################################################################
  739.  
  740. ; DCX_CACHE = 0x2
  741. ; DCX_CLIPCHILDREN = 0x8
  742. ; DCX_CLIPSIBLINGS = 0x10
  743. ; DCX_EXCLUDERGN = 0x40
  744. ; DCX_EXCLUDEUPDATE = 0x100
  745. ; DCX_INTERSECTRGN = 0x80
  746. ; DCX_INTERSECTUPDATE = 0x200
  747. ; DCX_LOCKWINDOWUPDATE = 0x400
  748. ; DCX_NORECOMPUTE = 0x100000
  749. ; DCX_NORESETATTRS = 0x4
  750. ; DCX_PARENTCLIP = 0x20
  751. ; DCX_VALIDATE = 0x200000
  752. ; DCX_WINDOW = 0x1
  753.  
  754. GetDCEx(hwnd, flags=0, hrgnClip=0)
  755. {
  756. return DllCall("GetDCEx", "uint", hwnd, "uint", hrgnClip, "int", flags)
  757. }
  758.  
  759. ;#####################################################################################
  760.  
  761. ; Function ReleaseDC
  762. ; Description This function releases a device context (DC), freeing it for use by other applications. The effect of ReleaseDC depends on the type of device context
  763. ;
  764. ; hdc Handle to the device context to be released
  765. ; hwnd Handle to the window whose device context is to be released
  766. ;
  767. ; return 1 = released
  768. ; 0 = not released
  769. ;
  770. ; notes The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common device context
  771. ; An application cannot use the ReleaseDC function to release a device context that was created by calling the CreateDC function; instead, it must use the DeleteDC function.
  772.  
  773. ReleaseDC(hdc, hwnd=0)
  774. {
  775. return DllCall("ReleaseDC", "uint", hwnd, "uint", hdc)
  776. }
  777.  
  778. ;#####################################################################################
  779.  
  780. ; Function DeleteDC
  781. ; Description The DeleteDC function deletes the specified device context (DC)
  782. ;
  783. ; hdc A handle to the device context
  784. ;
  785. ; return If the function succeeds, the return value is nonzero
  786. ;
  787. ; notes An application must not delete a DC whose handle was obtained by calling the GetDC function. Instead, it must call the ReleaseDC function to free the DC
  788.  
  789. DeleteDC(hdc)
  790. {
  791. return DllCall("DeleteDC", "uint", hdc)
  792. }
  793. ;#####################################################################################
  794.  
  795. ; Function Gdip_LibraryVersion
  796. ; Description Get the current library version
  797. ;
  798. ; return the library version
  799. ;
  800. ; notes This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts
  801.  
  802. Gdip_LibraryVersion()
  803. {
  804. return 1.45
  805. }
  806.  
  807. ;#####################################################################################
  808.  
  809. ; Function: Gdip_BitmapFromBRA
  810. ; Description: Gets a pointer to a gdi+ bitmap from a BRA file
  811. ;
  812. ; BRAFromMemIn The variable for a BRA file read to memory
  813. ; File The name of the file, or its number that you would like (This depends on alternate parameter)
  814. ; Alternate Changes whether the File parameter is the file name or its number
  815. ;
  816. ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap
  817. ; -1 = The BRA variable is empty
  818. ; -2 = The BRA has an incorrect header
  819. ; -3 = The BRA has information missing
  820. ; -4 = Could not find file inside the BRA
  821.  
  822. Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
  823. {
  824. if !BRAFromMemIn
  825. return -1
  826. Loop, Parse, BRAFromMemIn, `n
  827. {
  828. if (A_Index = 1)
  829. {
  830. StringSplit, Header, A_LoopField, |
  831. if (Header0 != 4 || Header2 != "BRA!")
  832. return -2
  833. }
  834. else if (A_Index = 2)
  835. {
  836. StringSplit, Info, A_LoopField, |
  837. if (Info0 != 3)
  838. return -3
  839. }
  840. else
  841. break
  842. }
  843. if !Alternate
  844. StringReplace, File, File, \, \\, All
  845. RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo)
  846. if !FileInfo
  847. return -4
  848.  
  849. hData := DllCall("GlobalAlloc", "uint", 2, "uint", FileInfo2)
  850. pData := DllCall("GlobalLock", "uint", hData)
  851. DllCall("RtlMoveMemory", "uint", pData, "uint", &BRAFromMemIn+Info2+FileInfo1, "uint", FileInfo2)
  852. DllCall("GlobalUnlock", "uint", hData)
  853. DllCall("ole32\CreateStreamOnHGlobal", "uint", hData, "int", 1, "uint*", pStream)
  854. DllCall("gdiplus\GdipCreateBitmapFromStream", "uint", pStream, "uint*", pBitmap)
  855. DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)
  856. return pBitmap
  857. }
  858.  
  859. ;#####################################################################################
  860.  
  861. ; Function Gdip_DrawRectangle
  862. ; Description This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap
  863. ;
  864. ; pGraphics Pointer to the Graphics of a bitmap
  865. ; pPen Pointer to a pen
  866. ; x x-coordinate of the top left of the rectangle
  867. ; y y-coordinate of the top left of the rectangle
  868. ; w width of the rectanlge
  869. ; h height of the rectangle
  870. ;
  871. ; return status enumeration. 0 = success
  872. ;
  873. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  874.  
  875. Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  876. {
  877. return DllCall("gdiplus\GdipDrawRectangle", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h)
  878. }
  879.  
  880. ;#####################################################################################
  881.  
  882. ; Function Gdip_DrawRoundedRectangle
  883. ; Description This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap
  884. ;
  885. ; pGraphics Pointer to the Graphics of a bitmap
  886. ; pPen Pointer to a pen
  887. ; x x-coordinate of the top left of the rounded rectangle
  888. ; y y-coordinate of the top left of the rounded rectangle
  889. ; w width of the rectanlge
  890. ; h height of the rectangle
  891. ; r radius of the rounded corners
  892. ;
  893. ; return status enumeration. 0 = success
  894. ;
  895. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  896.  
  897. Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
  898. {
  899. Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  900. Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  901. Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  902. Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  903. E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  904. Gdip_ResetClip(pGraphics)
  905. Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  906. Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  907. Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
  908. Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
  909. Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
  910. Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  911. Gdip_ResetClip(pGraphics)
  912. return E
  913. }
  914.  
  915. ;#####################################################################################
  916.  
  917. ; Function Gdip_DrawEllipse
  918. ; Description This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap
  919. ;
  920. ; pGraphics Pointer to the Graphics of a bitmap
  921. ; pPen Pointer to a pen
  922. ; x x-coordinate of the top left of the rectangle the ellipse will be drawn into
  923. ; y y-coordinate of the top left of the rectangle the ellipse will be drawn into
  924. ; w width of the ellipse
  925. ; h height of the ellipse
  926. ;
  927. ; return status enumeration. 0 = success
  928. ;
  929. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  930.  
  931. Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h)
  932. {
  933. return DllCall("gdiplus\GdipDrawEllipse", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h)
  934. }
  935.  
  936. ;#####################################################################################
  937.  
  938. ; Function Gdip_DrawBezier
  939. ; Description This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap
  940. ;
  941. ; pGraphics Pointer to the Graphics of a bitmap
  942. ; pPen Pointer to a pen
  943. ; x1 x-coordinate of the start of the bezier
  944. ; y1 y-coordinate of the start of the bezier
  945. ; x2 x-coordinate of the first arc of the bezier
  946. ; y2 y-coordinate of the first arc of the bezier
  947. ; x3 x-coordinate of the second arc of the bezier
  948. ; y3 y-coordinate of the second arc of the bezier
  949. ; x4 x-coordinate of the end of the bezier
  950. ; y4 y-coordinate of the end of the bezier
  951. ;
  952. ; return status enumeration. 0 = success
  953. ;
  954. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  955.  
  956. Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
  957. {
  958. return DllCall("gdiplus\GdipDrawBezier", "uint", pgraphics, "uint", pPen
  959. , "float", x1, "float", y1, "float", x2, "float", y2
  960. , "float", x3, "float", y3, "float", x4, "float", y4)
  961. }
  962.  
  963. ;#####################################################################################
  964.  
  965. ; Function Gdip_DrawArc
  966. ; Description This function uses a pen to draw the outline of an arc into the Graphics of a bitmap
  967. ;
  968. ; pGraphics Pointer to the Graphics of a bitmap
  969. ; pPen Pointer to a pen
  970. ; x x-coordinate of the start of the arc
  971. ; y y-coordinate of the start of the arc
  972. ; w width of the arc
  973. ; h height of the arc
  974. ; StartAngle specifies the angle between the x-axis and the starting point of the arc
  975. ; SweepAngle specifies the angle between the starting and ending points of the arc
  976. ;
  977. ; return status enumeration. 0 = success
  978. ;
  979. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  980.  
  981. Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  982. {
  983. return DllCall("gdiplus\GdipDrawArc", "uint", pGraphics, "uint", pPen, "float", x
  984. , "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  985. }
  986.  
  987. ;#####################################################################################
  988.  
  989. ; Function Gdip_DrawPie
  990. ; Description This function uses a pen to draw the outline of a pie into the Graphics of a bitmap
  991. ;
  992. ; pGraphics Pointer to the Graphics of a bitmap
  993. ; pPen Pointer to a pen
  994. ; x x-coordinate of the start of the pie
  995. ; y y-coordinate of the start of the pie
  996. ; w width of the pie
  997. ; h height of the pie
  998. ; StartAngle specifies the angle between the x-axis and the starting point of the pie
  999. ; SweepAngle specifies the angle between the starting and ending points of the pie
  1000. ;
  1001. ; return status enumeration. 0 = success
  1002. ;
  1003. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1004.  
  1005. Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1006. {
  1007. return DllCall("gdiplus\GdipDrawPie", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  1008. }
  1009.  
  1010. ;#####################################################################################
  1011.  
  1012. ; Function Gdip_DrawLine
  1013. ; Description This function uses a pen to draw a line into the Graphics of a bitmap
  1014. ;
  1015. ; pGraphics Pointer to the Graphics of a bitmap
  1016. ; pPen Pointer to a pen
  1017. ; x1 x-coordinate of the start of the line
  1018. ; y1 y-coordinate of the start of the line
  1019. ; x2 x-coordinate of the end of the line
  1020. ; y2 y-coordinate of the end of the line
  1021. ;
  1022. ; return status enumeration. 0 = success
  1023.  
  1024. Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
  1025. {
  1026. return DllCall("gdiplus\GdipDrawLine", "uint", pGraphics, "uint", pPen
  1027. , "float", x1, "float", y1, "float", x2, "float", y2)
  1028. }
  1029.  
  1030. ;#####################################################################################
  1031.  
  1032. ; Function Gdip_DrawLines
  1033. ; Description This function uses a pen to draw a series of joined lines into the Graphics of a bitmap
  1034. ;
  1035. ; pGraphics Pointer to the Graphics of a bitmap
  1036. ; pPen Pointer to a pen
  1037. ; Points the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1038. ;
  1039. ; return status enumeration. 0 = success
  1040.  
  1041. Gdip_DrawLines(pGraphics, pPen, Points)
  1042. {
  1043. StringSplit, Points, Points, |
  1044. VarSetCapacity(PointF, 8*Points0)
  1045. Loop, %Points0%
  1046. {
  1047. StringSplit, Coord, Points%A_Index%, `,
  1048. NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1049. }
  1050. return DllCall("gdiplus\GdipDrawLines", "uint", pGraphics, "uint", pPen, "uint", &PointF, "int", Points0)
  1051. }
  1052.  
  1053. ;#####################################################################################
  1054.  
  1055. ; Function Gdip_FillRectangle
  1056. ; Description This function uses a brush to fill a rectangle in the Graphics of a bitmap
  1057. ;
  1058. ; pGraphics Pointer to the Graphics of a bitmap
  1059. ; pBrush Pointer to a brush
  1060. ; x x-coordinate of the top left of the rectangle
  1061. ; y y-coordinate of the top left of the rectangle
  1062. ; w width of the rectanlge
  1063. ; h height of the rectangle
  1064. ;
  1065. ; return status enumeration. 0 = success
  1066.  
  1067. Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1068. {
  1069. return DllCall("gdiplus\GdipFillRectangle", "uint", pGraphics, "int", pBrush
  1070. , "float", x, "float", y, "float", w, "float", h)
  1071. }
  1072.  
  1073. ;#####################################################################################
  1074.  
  1075. ; Function Gdip_FillRoundedRectangle
  1076. ; Description This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap
  1077. ;
  1078. ; pGraphics Pointer to the Graphics of a bitmap
  1079. ; pBrush Pointer to a brush
  1080. ; x x-coordinate of the top left of the rounded rectangle
  1081. ; y y-coordinate of the top left of the rounded rectangle
  1082. ; w width of the rectanlge
  1083. ; h height of the rectangle
  1084. ; r radius of the rounded corners
  1085. ;
  1086. ; return status enumeration. 0 = success
  1087.  
  1088. Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
  1089. {
  1090. Region := Gdip_GetClipRegion(pGraphics)
  1091. Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  1092. Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  1093. Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  1094. Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  1095. E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1096. Gdip_SetClipRegion(pGraphics, Region, 0)
  1097. Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  1098. Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  1099. Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
  1100. Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
  1101. Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
  1102. Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  1103. Gdip_SetClipRegion(pGraphics, Region, 0)
  1104. Gdip_DeleteRegion(Region)
  1105. return E
  1106. }
  1107.  
  1108. ;#####################################################################################
  1109.  
  1110. ; Function Gdip_FillPolygon
  1111. ; Description This function uses a brush to fill a polygon in the Graphics of a bitmap
  1112. ;
  1113. ; pGraphics Pointer to the Graphics of a bitmap
  1114. ; pBrush Pointer to a brush
  1115. ; Points the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1116. ;
  1117. ; return status enumeration. 0 = success
  1118. ;
  1119. ; notes Alternate will fill the polygon as a whole, wheras winding will fill each new "segment"
  1120. ; Alternate = 0
  1121. ; Winding = 1
  1122.  
  1123. Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
  1124. {
  1125. StringSplit, Points, Points, |
  1126. VarSetCapacity(PointF, 8*Points0)
  1127. Loop, %Points0%
  1128. {
  1129. StringSplit, Coord, Points%A_Index%, `,
  1130. NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1131. }
  1132. return DllCall("gdiplus\GdipFillPolygon", "uint", pGraphics, "uint", pBrush, "uint", &PointF, "int", Points0, "int", FillMode)
  1133. }
  1134.  
  1135. ;#####################################################################################
  1136.  
  1137. ; Function Gdip_FillPie
  1138. ; Description This function uses a brush to fill a pie in the Graphics of a bitmap
  1139. ;
  1140. ; pGraphics Pointer to the Graphics of a bitmap
  1141. ; pBrush Pointer to a brush
  1142. ; x x-coordinate of the top left of the pie
  1143. ; y y-coordinate of the top left of the pie
  1144. ; w width of the pie
  1145. ; h height of the pie
  1146. ; StartAngle specifies the angle between the x-axis and the starting point of the pie
  1147. ; SweepAngle specifies the angle between the starting and ending points of the pie
  1148. ;
  1149. ; return status enumeration. 0 = success
  1150.  
  1151. Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
  1152. {
  1153. return DllCall("gdiplus\GdipFillPie", "uint", pGraphics, "uint", pBrush
  1154. , "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  1155. }
  1156.  
  1157. ;#####################################################################################
  1158.  
  1159. ; Function Gdip_FillEllipse
  1160. ; Description This function uses a brush to fill an ellipse in the Graphics of a bitmap
  1161. ;
  1162. ; pGraphics Pointer to the Graphics of a bitmap
  1163. ; pBrush Pointer to a brush
  1164. ; x x-coordinate of the top left of the ellipse
  1165. ; y y-coordinate of the top left of the ellipse
  1166. ; w width of the ellipse
  1167. ; h height of the ellipse
  1168. ;
  1169. ; return status enumeration. 0 = success
  1170.  
  1171. Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h)
  1172. {
  1173. return DllCall("gdiplus\GdipFillEllipse", "uint", pGraphics, "uint", pBrush, "float", x, "float", y, "float", w, "float", h)
  1174. }
  1175.  
  1176. ;#####################################################################################
  1177.  
  1178. ; Function Gdip_FillRegion
  1179. ; Description This function uses a brush to fill a region in the Graphics of a bitmap
  1180. ;
  1181. ; pGraphics Pointer to the Graphics of a bitmap
  1182. ; pBrush Pointer to a brush
  1183. ; Region Pointer to a Region
  1184. ;
  1185. ; return status enumeration. 0 = success
  1186. ;
  1187. ; notes You can create a region Gdip_CreateRegion() and then add to this
  1188.  
  1189. Gdip_FillRegion(pGraphics, pBrush, Region)
  1190. {
  1191. return DllCall("gdiplus\GdipFillRegion", "uint", pGraphics, "uint", pBrush, "uint", Region)
  1192. }
  1193.  
  1194. ;#####################################################################################
  1195.  
  1196. ; Function Gdip_FillPath
  1197. ; Description This function uses a brush to fill a path in the Graphics of a bitmap
  1198. ;
  1199. ; pGraphics Pointer to the Graphics of a bitmap
  1200. ; pBrush Pointer to a brush
  1201. ; Region Pointer to a Path
  1202. ;
  1203. ; return status enumeration. 0 = success
  1204.  
  1205. Gdip_FillPath(pGraphics, pBrush, Path)
  1206. {
  1207. return DllCall("gdiplus\GdipFillPath", "uint", pGraphics, "uint", pBrush, "uint", Path)
  1208. }
  1209.  
  1210. ;#####################################################################################
  1211.  
  1212. ; Function Gdip_DrawImagePointsRect
  1213. ; Description This function draws a bitmap into the Graphics of another bitmap and skews it
  1214. ;
  1215. ; pGraphics Pointer to the Graphics of a bitmap
  1216. ; pBitmap Pointer to a bitmap to be drawn
  1217. ; Points Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap
  1218. ; sx x-coordinate of source upper-left corner
  1219. ; sy y-coordinate of source upper-left corner
  1220. ; sw width of source rectangle
  1221. ; sh height of source rectangle
  1222. ; Matrix a matrix used to alter image attributes when drawing
  1223. ;
  1224. ; return status enumeration. 0 = success
  1225. ;
  1226. ; notes if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1227. ; Matrix can be omitted to just draw with no alteration to ARGB
  1228. ; Matrix may be passed as a digit from 0 - 1 to change just transparency
  1229. ; Matrix can be passed as a matrix with any delimiter
  1230.  
  1231. Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
  1232. {
  1233. StringSplit, Points, Points, |
  1234. VarSetCapacity(PointF, 8*Points0)
  1235. Loop, %Points0%
  1236. {
  1237. StringSplit, Coord, Points%A_Index%, `,
  1238. NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1239. }
  1240.  
  1241. if (Matrix&1 = "")
  1242. ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1243. else if (Matrix != 1)
  1244. ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
  1245.  
  1246. if (sx = "" && sy = "" && sw = "" && sh = "")
  1247. {
  1248. sx := 0, sy := 0
  1249. sw := Gdip_GetImageWidth(pBitmap)
  1250. sh := Gdip_GetImageHeight(pBitmap)
  1251. }
  1252.  
  1253. E := DllCall("gdiplus\GdipDrawImagePointsRect", "uint", pGraphics, "uint", pBitmap
  1254. , "uint", &PointF, "int", Points0, "float", sx, "float", sy, "float", sw, "float", sh
  1255. , "int", 2, "uint", ImageAttr, "uint", 0, "uint", 0)
  1256. if ImageAttr
  1257. Gdip_DisposeImageAttributes(ImageAttr)
  1258. return E
  1259. }
  1260.  
  1261. ;#####################################################################################
  1262.  
  1263. ; Function Gdip_DrawImage
  1264. ; Description This function draws a bitmap into the Graphics of another bitmap
  1265. ;
  1266. ; pGraphics Pointer to the Graphics of a bitmap
  1267. ; pBitmap Pointer to a bitmap to be drawn
  1268. ; dx x-coord of destination upper-left corner
  1269. ; dy y-coord of destination upper-left corner
  1270. ; dw width of destination image
  1271. ; dh height of destination image
  1272. ; sx x-coordinate of source upper-left corner
  1273. ; sy y-coordinate of source upper-left corner
  1274. ; sw width of source image
  1275. ; sh height of source image
  1276. ; Matrix a matrix used to alter image attributes when drawing
  1277. ;
  1278. ; return status enumeration. 0 = success
  1279. ;
  1280. ; notes if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1281. ; Gdip_DrawImage performs faster
  1282. ; Matrix can be omitted to just draw with no alteration to ARGB
  1283. ; Matrix may be passed as a digit from 0 - 1 to change just transparency
  1284. ; Matrix can be passed as a matrix with any delimiter. For example:
  1285. ; MatrixBright=
  1286. ; (
  1287. ; 1.5 |0 |0 |0 |0
  1288. ; 0 |1.5 |0 |0 |0
  1289. ; 0 |0 |1.5 |0 |0
  1290. ; 0 |0 |0 |1 |0
  1291. ; 0.05 |0.05 |0.05 |0 |1
  1292. ; )
  1293. ;
  1294. ; notes MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
  1295. ; MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
  1296. ; MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1
  1297.  
  1298. Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
  1299. {
  1300. if (Matrix&1 = "")
  1301. ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1302. else if (Matrix != 1)
  1303. ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
  1304.  
  1305. if (sx = "" && sy = "" && sw = "" && sh = "")
  1306. {
  1307. if (dx = "" && dy = "" && dw = "" && dh = "")
  1308. {
  1309. sx := dx := 0, sy := dy := 0
  1310. sw := dw := Gdip_GetImageWidth(pBitmap)
  1311. sh := dh := Gdip_GetImageHeight(pBitmap)
  1312. }
  1313. else
  1314. {
  1315. sx := sy := 0
  1316. sw := Gdip_GetImageWidth(pBitmap)
  1317. sh := Gdip_GetImageHeight(pBitmap)
  1318. }
  1319. }
  1320.  
  1321. E := DllCall("gdiplus\GdipDrawImageRectRect", "uint", pGraphics, "uint", pBitmap
  1322. , "float", dx, "float", dy, "float", dw, "float", dh
  1323. , "float", sx, "float", sy, "float", sw, "float", sh
  1324. , "int", 2, "uint", ImageAttr, "uint", 0, "uint", 0)
  1325. if ImageAttr
  1326. Gdip_DisposeImageAttributes(ImageAttr)
  1327. return E
  1328. }
  1329.  
  1330. ;#####################################################################################
  1331.  
  1332. ; Function Gdip_SetImageAttributesColorMatrix
  1333. ; Description This function creates an image matrix ready for drawing
  1334. ;
  1335. ; Matrix a matrix used to alter image attributes when drawing
  1336. ; passed with any delimeter
  1337. ;
  1338. ; return returns an image matrix on sucess or 0 if it fails
  1339. ;
  1340. ; notes MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
  1341. ; MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
  1342. ; MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1
  1343.  
  1344. Gdip_SetImageAttributesColorMatrix(Matrix)
  1345. {
  1346. VarSetCapacity(ColourMatrix, 100, 0)
  1347. Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
  1348. StringSplit, Matrix, Matrix, |
  1349. Loop, 25
  1350. {
  1351. Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
  1352. NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
  1353. }
  1354. DllCall("gdiplus\GdipCreateImageAttributes", "uint*", ImageAttr)
  1355. DllCall("gdiplus\GdipSetImageAttributesColorMatrix", "uint", ImageAttr, "int", 1, "int", 1, "uint", &ColourMatrix, "int", 0, "int", 0)
  1356. return ImageAttr
  1357. }
  1358.  
  1359. ;#####################################################################################
  1360.  
  1361. ; Function Gdip_GraphicsFromImage
  1362. ; Description This function gets the graphics for a bitmap used for drawing functions
  1363. ;
  1364. ; pBitmap Pointer to a bitmap to get the pointer to its graphics
  1365. ;
  1366. ; return returns a pointer to the graphics of a bitmap
  1367. ;
  1368. ; notes a bitmap can be drawn into the graphics of another bitmap
  1369.  
  1370. Gdip_GraphicsFromImage(pBitmap)
  1371. {
  1372. DllCall("gdiplus\GdipGetImageGraphicsContext", "uint", pBitmap, "uint*", pGraphics)
  1373. return pGraphics
  1374. }
  1375.  
  1376. ;#####################################################################################
  1377.  
  1378. ; Function Gdip_GraphicsFromHDC
  1379. ; Description This function gets the graphics from the handle to a device context
  1380. ;
  1381. ; hdc This is the handle to the device context
  1382. ;
  1383. ; return returns a pointer to the graphics of a bitmap
  1384. ;
  1385. ; notes You can draw a bitmap into the graphics of another bitmap
  1386.  
  1387. Gdip_GraphicsFromHDC(hdc)
  1388. {
  1389. DllCall("gdiplus\GdipCreateFromHDC", "uint", hdc, "uint*", pGraphics)
  1390. return pGraphics
  1391. }
  1392.  
  1393. ;#####################################################################################
  1394.  
  1395. ; Function Gdip_GetDC
  1396. ; Description This function gets the device context of the passed Graphics
  1397. ;
  1398. ; hdc This is the handle to the device context
  1399. ;
  1400. ; return returns the device context for the graphics of a bitmap
  1401.  
  1402. Gdip_GetDC(pGraphics)
  1403. {
  1404. DllCall("gdiplus\GdipGetDC", "uint", pGraphics, "uint*", hdc)
  1405. return hdc
  1406. }
  1407.  
  1408. ;#####################################################################################
  1409.  
  1410. ; Function Gdip_ReleaseDC
  1411. ; Description This function releases a device context from use for further use
  1412. ;
  1413. ; pGraphics Pointer to the graphics of a bitmap
  1414. ; hdc This is the handle to the device context
  1415. ;
  1416. ; return status enumeration. 0 = success
  1417.  
  1418. Gdip_ReleaseDC(pGraphics, hdc)
  1419. {
  1420. return DllCall("gdiplus\GdipReleaseDC", "uint", pGraphics, "uint", hdc)
  1421. }
  1422.  
  1423. ;#####################################################################################
  1424.  
  1425. ; Function Gdip_GraphicsClear
  1426. ; Description Clears the graphics of a bitmap ready for further drawing
  1427. ;
  1428. ; pGraphics Pointer to the graphics of a bitmap
  1429. ; ARGB The colour to clear the graphics to
  1430. ;
  1431. ; return status enumeration. 0 = success
  1432. ;
  1433. ; notes By default this will make the background invisible
  1434. ; Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics
  1435.  
  1436. Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
  1437. {
  1438. return DllCall("gdiplus\GdipGraphicsClear", "uint", pGraphics, "int", ARGB)
  1439. }
  1440.  
  1441. ;#####################################################################################
  1442.  
  1443. ; Function Gdip_BlurBitmap
  1444. ; Description Gives a pointer to a blurred bitmap from a pointer to a bitmap
  1445. ;
  1446. ; pBitmap Pointer to a bitmap to be blurred
  1447. ; Blur The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur)
  1448. ;
  1449. ; return If the function succeeds, the return value is a pointer to the new blurred bitmap
  1450. ; -1 = The blur parameter is outside the range 1-100
  1451. ;
  1452. ; notes This function will not dispose of the original bitmap
  1453.  
  1454. Gdip_BlurBitmap(pBitmap, Blur)
  1455. {
  1456. if (Blur > 100) || (Blur < 1)
  1457. return -1
  1458.  
  1459. sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
  1460. dWidth := sWidth//Blur, dHeight := sHeight//Blur
  1461.  
  1462. pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
  1463. G1 := Gdip_GraphicsFromImage(pBitmap1)
  1464. Gdip_SetInterpolationMode(G1, 7)
  1465. Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
  1466.  
  1467. Gdip_DeleteGraphics(G1)
  1468.  
  1469. pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
  1470. G2 := Gdip_GraphicsFromImage(pBitmap2)
  1471. Gdip_SetInterpolationMode(G2, 7)
  1472. Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
  1473.  
  1474. Gdip_DeleteGraphics(G2)
  1475. Gdip_DisposeImage(pBitmap1)
  1476. return pBitmap2
  1477. }
  1478.  
  1479. ;#####################################################################################
  1480.  
  1481. ; Function: Gdip_SaveBitmapToFile
  1482. ; Description: Saves a bitmap to a file in any supported format onto disk
  1483. ;
  1484. ; pBitmap Pointer to a bitmap
  1485. ; sOutput The name of the file that the bitmap will be saved to. Supported extensions are: .BMP,.DIB,.RLE,.JPG,.JPEG,.JPE,.JFIF,.GIF,.TIF,.TIFF,.PNG
  1486. ; Quality If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality
  1487. ;
  1488. ; return If the function succeeds, the return value is zero, otherwise:
  1489. ; -1 = Extension supplied is not a supported file format
  1490. ; -2 = Could not get a list of encoders on system
  1491. ; -3 = Could not find matching encoder for specified file format
  1492. ; -4 = Could not get WideChar name of output file
  1493. ; -5 = Could not save file to disk
  1494. ;
  1495. ; notes This function will use the extension supplied from the sOutput parameter to determine the output format
  1496.  
  1497. Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
  1498. {
  1499. SplitPath, sOutput,,, Extension
  1500. if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
  1501. return -1
  1502. Extension := "." Extension
  1503.  
  1504. DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
  1505. VarSetCapacity(ci, nSize)
  1506. DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, "uint", &ci)
  1507. if !(nCount && nSize)
  1508. return -2
  1509.  
  1510. Loop, %nCount%
  1511. {
  1512. Location := NumGet(ci, 76*(A_Index-1)+44)
  1513. if !A_IsUnicode
  1514. {
  1515. nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0)
  1516. VarSetCapacity(sString, nSize)
  1517. DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
  1518. if !InStr(sString, "*" Extension)
  1519. continue
  1520. }
  1521. else
  1522. {
  1523. nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0)
  1524. sString := ""
  1525. Loop, %nSize%
  1526. sString .= Chr(NumGet(Location+0, 2*(A_Index-1), "char"))
  1527. if !InStr(sString, "*" Extension)
  1528. continue
  1529. }
  1530. pCodec := &ci+76*(A_Index-1)
  1531. break
  1532. }
  1533. if !pCodec
  1534. return -3
  1535.  
  1536. if (Quality != 75)
  1537. {
  1538. Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
  1539. if Extension in .JPG,.JPEG,.JPE,.JFIF
  1540. {
  1541. DllCall("gdiplus\GdipGetEncoderParameterListSize", "uint", pBitmap, "uint", pCodec, "uint*", nSize)
  1542. VarSetCapacity(EncoderParameters, nSize, 0)
  1543. DllCall("gdiplus\GdipGetEncoderParameterList", "uint", pBitmap, "uint", pCodec, "uint", nSize, "uint", &EncoderParameters)
  1544. Loop, % NumGet(EncoderParameters) ;%
  1545. {
  1546. if (NumGet(EncoderParameters, (28*(A_Index-1))+20) = 1) && (NumGet(EncoderParameters, (28*(A_Index-1))+24) = 6)
  1547. {
  1548. p := (28*(A_Index-1))+&EncoderParameters
  1549. NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20)))
  1550. break
  1551. }
  1552. }
  1553. }
  1554. }
  1555.  
  1556. if !A_IsUnicode
  1557. {
  1558. nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sOutput, "int", -1, "uint", 0, "int", 0)
  1559. VarSetCapacity(wOutput, nSize*2)
  1560. DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sOutput, "int", -1, "uint", &wOutput, "int", nSize)
  1561. VarSetCapacity(wOutput, -1)
  1562. if !VarSetCapacity(wOutput)
  1563. return -4
  1564. E := DllCall("gdiplus\GdipSaveImageToFile", "uint", pBitmap, "uint", &wOutput, "uint", pCodec, "uint", p ? p : 0)
  1565. }
  1566. else
  1567. E := DllCall("gdiplus\GdipSaveImageToFile", "uint", pBitmap, "uint", &sOutput, "uint", pCodec, "uint", p ? p : 0)
  1568. return E ? -5 : 0
  1569. }
  1570.  
  1571. ;#####################################################################################
  1572.  
  1573. ; Function Gdip_GetPixel
  1574. ; Description Gets the ARGB of a pixel in a bitmap
  1575. ;
  1576. ; pBitmap Pointer to a bitmap
  1577. ; x x-coordinate of the pixel
  1578. ; y y-coordinate of the pixel
  1579. ;
  1580. ; return Returns the ARGB value of the pixel
  1581.  
  1582. Gdip_GetPixel(pBitmap, x, y)
  1583. {
  1584. DllCall("gdiplus\GdipBitmapGetPixel", "uint", pBitmap, "int", x, "int", y, "uint*", ARGB)
  1585. return ARGB
  1586. }
  1587.  
  1588. ;#####################################################################################
  1589.  
  1590. ; Function Gdip_SetPixel
  1591. ; Description Sets the ARGB of a pixel in a bitmap
  1592. ;
  1593. ; pBitmap Pointer to a bitmap
  1594. ; x x-coordinate of the pixel
  1595. ; y y-coordinate of the pixel
  1596. ;
  1597. ; return status enumeration. 0 = success
  1598.  
  1599. Gdip_SetPixel(pBitmap, x, y, ARGB)
  1600. {
  1601. return DllCall("gdiplus\GdipBitmapSetPixel", "uint", pBitmap, "int", x, "int", y, "int", ARGB)
  1602. }
  1603.  
  1604. ;#####################################################################################
  1605.  
  1606. ; Function Gdip_GetImageWidth
  1607. ; Description Gives the width of a bitmap
  1608. ;
  1609. ; pBitmap Pointer to a bitmap
  1610. ;
  1611. ; return Returns the width in pixels of the supplied bitmap
  1612.  
  1613. Gdip_GetImageWidth(pBitmap)
  1614. {
  1615. DllCall("gdiplus\GdipGetImageWidth", "uint", pBitmap, "uint*", Width)
  1616. return Width
  1617. }
  1618.  
  1619. ;#####################################################################################
  1620.  
  1621. ; Function Gdip_GetImageHeight
  1622. ; Description Gives the height of a bitmap
  1623. ;
  1624. ; pBitmap Pointer to a bitmap
  1625. ;
  1626. ; return Returns the height in pixels of the supplied bitmap
  1627.  
  1628. Gdip_GetImageHeight(pBitmap)
  1629. {
  1630. DllCall("gdiplus\GdipGetImageHeight", "uint", pBitmap, "uint*", Height)
  1631. return Height
  1632. }
  1633.  
  1634. ;#####################################################################################
  1635.  
  1636. ; Function Gdip_GetDimensions
  1637. ; Description Gives the width and height of a bitmap
  1638. ;
  1639. ; pBitmap Pointer to a bitmap
  1640. ; Width ByRef variable. This variable will be set to the width of the bitmap
  1641. ; Height ByRef variable. This variable will be set to the height of the bitmap
  1642. ;
  1643. ; return No return value
  1644. ; Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  1645.  
  1646. Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height)
  1647. {
  1648. DllCall("gdiplus\GdipGetImageWidth", "uint", pBitmap, "uint*", Width)
  1649. DllCall("gdiplus\GdipGetImageHeight", "uint", pBitmap, "uint*", Height)
  1650. }
  1651.  
  1652. ;#####################################################################################
  1653.  
  1654. Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height)
  1655. {
  1656. Gdip_GetImageDimensions(pBitmap, Width, Height)
  1657. }
  1658.  
  1659. ;#####################################################################################
  1660.  
  1661. Gdip_GetImagePixelFormat(pBitmap)
  1662. {
  1663. DllCall("gdiplus\GdipGetImagePixelFormat", "uint", pBitmap, "uint*", Format)
  1664. return Format
  1665. }
  1666.  
  1667. ;#####################################################################################
  1668.  
  1669. ; Function Gdip_GetDpiX
  1670. ; Description Gives the horizontal dots per inch of the graphics of a bitmap
  1671. ;
  1672. ; pBitmap Pointer to a bitmap
  1673. ; Width ByRef variable. This variable will be set to the width of the bitmap
  1674. ; Height ByRef variable. This variable will be set to the height of the bitmap
  1675. ;
  1676. ; return No return value
  1677. ; Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  1678.  
  1679. Gdip_GetDpiX(pGraphics)
  1680. {
  1681. DllCall("gdiplus\GdipGetDpiX", "uint", pGraphics, "float*", dpix)
  1682. return Round(dpix)
  1683. }
  1684.  
  1685. ;#####################################################################################
  1686.  
  1687. Gdip_GetDpiY(pGraphics)
  1688. {
  1689. DllCall("gdiplus\GdipGetDpiY", "uint", pGraphics, "float*", dpiy)
  1690. return Round(dpiy)
  1691. }
  1692.  
  1693. ;#####################################################################################
  1694.  
  1695. Gdip_GetImageHorizontalResolution(pBitmap)
  1696. {
  1697. DllCall("gdiplus\GdipGetImageHorizontalResolution", "uint", pBitmap, "float*", dpix)
  1698. return Round(dpix)
  1699. }
  1700.  
  1701. ;#####################################################################################
  1702.  
  1703. Gdip_GetImageVerticalResolution(pBitmap)
  1704. {
  1705. DllCall("gdiplus\GdipGetImageVerticalResolution", "uint", pBitmap, "float*", dpiy)
  1706. return Round(dpiy)
  1707. }
  1708.  
  1709. ;#####################################################################################
  1710.  
  1711. Gdip_BitmapSetResolution(pBitmap, dpix, dpiy)
  1712. {
  1713. return DllCall("gdiplus\GdipBitmapSetResolution", "uint", pBitmap, "float", dpix, "float", dpiy)
  1714. }
  1715.  
  1716. ;#####################################################################################
  1717.  
  1718. Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
  1719. {
  1720. SplitPath, sFile,,, ext
  1721. if ext in exe,dll
  1722. {
  1723. Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
  1724. VarSetCapacity(buf, 40)
  1725. Loop, Parse, Sizes, |
  1726. {
  1727. DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, "uint*", hIcon, "uint*", 0, "uint", 1, "uint", 0)
  1728. if !hIcon
  1729. continue
  1730.  
  1731. if !DllCall("GetIconInfo", "uint", hIcon, "uint", &buf)
  1732. {
  1733. DestroyIcon(hIcon)
  1734. continue
  1735. }
  1736. hbmColor := NumGet(buf, 16)
  1737. hbmMask := NumGet(buf, 12)
  1738.  
  1739. if !(hbmColor && DllCall("GetObject", "uint", hbmColor, "int", 24, "uint", &buf))
  1740. {
  1741. DestroyIcon(hIcon)
  1742. continue
  1743. }
  1744. break
  1745. }
  1746. if !hIcon
  1747. return -1
  1748.  
  1749. Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int")
  1750. hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  1751.  
  1752. if !DllCall("DrawIconEx", "uint", hdc, "int", 0, "int", 0, "uint", hIcon, "uint", Width, "uint", Height, "uint", 0, "uint", 0, "uint", 3)
  1753. {
  1754. DestroyIcon(hIcon)
  1755. return -2
  1756. }
  1757.  
  1758. VarSetCapacity(dib, 84)
  1759. DllCall("GetObject", "uint", hbm, "int", 84, "uint", &dib)
  1760. Stride := NumGet(dib, 12), Bits := NumGet(dib, 20)
  1761.  
  1762. DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, "uint", Bits, "uint*", pBitmapOld)
  1763. pBitmap := Gdip_CreateBitmap(Width, Height), G := Gdip_GraphicsFromImage(pBitmap)
  1764. Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
  1765. SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  1766. Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld)
  1767. DestroyIcon(hIcon)
  1768. }
  1769. else
  1770. {
  1771. if !A_IsUnicode
  1772. {
  1773. VarSetCapacity(wFile, 1023)
  1774. DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sFile, "int", -1, "uint", &wFile, "int", 512)
  1775. DllCall("gdiplus\GdipCreateBitmapFromFile", "uint", &wFile, "uint*", pBitmap)
  1776. }
  1777. else
  1778. DllCall("gdiplus\GdipCreateBitmapFromFile", "uint", &sFile, "uint*", pBitmap)
  1779. }
  1780. return pBitmap
  1781. }
  1782.  
  1783. ;#####################################################################################
  1784.  
  1785. Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
  1786. {
  1787. DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "uint", hBitmap, "uint", Palette, "uint*", pBitmap)
  1788. return pBitmap
  1789. }
  1790.  
  1791. ;#####################################################################################
  1792.  
  1793. Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
  1794. {
  1795. DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "uint", pBitmap, "uint*", hbm, "int", Background)
  1796. return hbm
  1797. }
  1798.  
  1799. ;#####################################################################################
  1800.  
  1801. Gdip_CreateBitmapFromHICON(hIcon)
  1802. {
  1803. DllCall("gdiplus\GdipCreateBitmapFromHICON", "uint", hIcon, "uint*", pBitmap)
  1804. return pBitmap
  1805. }
  1806.  
  1807. ;#####################################################################################
  1808.  
  1809. Gdip_CreateHICONFromBitmap(pBitmap)
  1810. {
  1811. DllCall("gdiplus\GdipCreateHICONFromBitmap", "uint", pBitmap, "uint*", hIcon)
  1812. return hIcon
  1813. }
  1814.  
  1815. ;#####################################################################################
  1816.  
  1817. Gdip_CreateBitmap(Width, Height, Format=0x26200A)
  1818. {
  1819. DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, "uint", 0, "uint*", pBitmap)
  1820. Return pBitmap
  1821. }
  1822.  
  1823. ;#####################################################################################
  1824.  
  1825. Gdip_CreateBitmapFromClipboard()
  1826. {
  1827. if !DllCall("OpenClipboard", "uint", 0)
  1828. return -1
  1829. if !DllCall("IsClipboardFormatAvailable", "uint", 8)
  1830. return -2
  1831. if !hBitmap := DllCall("GetClipboardData", "uint", 2)
  1832. return -3
  1833. if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
  1834. return -4
  1835. if !DllCall("CloseClipboard")
  1836. return -5
  1837. DeleteObject(hBitmap)
  1838. return pBitmap
  1839. }
  1840.  
  1841. ;#####################################################################################
  1842.  
  1843. Gdip_SetBitmapToClipboard(pBitmap)
  1844. {
  1845. hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  1846. DllCall("GetObject", "uint", hBitmap, "int", VarSetCapacity(oi, 84, 0), "uint", &oi)
  1847. hdib := DllCall("GlobalAlloc", "uint", 2, "uint", 40+NumGet(oi, 44))
  1848. pdib := DllCall("GlobalLock", "uint", hdib)
  1849. DllCall("RtlMoveMemory", "uint", pdib, "uint", &oi+24, "uint", 40)
  1850. DllCall("RtlMoveMemory", "Uint", pdib+40, "Uint", NumGet(oi, 20), "uint", NumGet(oi, 44))
  1851. DllCall("GlobalUnlock", "uint", hdib)
  1852. DllCall("DeleteObject", "uint", hBitmap)
  1853. DllCall("OpenClipboard", "uint", 0)
  1854. DllCall("EmptyClipboard")
  1855. DllCall("SetClipboardData", "uint", 8, "uint", hdib)
  1856. DllCall("CloseClipboard")
  1857. }
  1858.  
  1859. ;#####################################################################################
  1860.  
  1861. Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
  1862. {
  1863. DllCall("gdiplus\GdipCloneBitmapArea", "float", x, "float", y, "float", w, "float", h
  1864. , "int", Format, "uint", pBitmap, "uint*", pBitmapDest)
  1865. return pBitmapDest
  1866. }
  1867.  
  1868. ;#####################################################################################
  1869. ; Create resources
  1870. ;#####################################################################################
  1871.  
  1872. Gdip_CreatePen(ARGB, w)
  1873. {
  1874. DllCall("gdiplus\GdipCreatePen1", "int", ARGB, "float", w, "int", 2, "uint*", pPen)
  1875. return pPen
  1876. }
  1877.  
  1878. ;#####################################################################################
  1879.  
  1880. Gdip_CreatePenFromBrush(pBrush, w)
  1881. {
  1882. DllCall("gdiplus\GdipCreatePen2", "uint", pBrush, "float", w, "int", 2, "uint*", pPen)
  1883. return pPen
  1884. }
  1885.  
  1886. ;#####################################################################################
  1887.  
  1888. Gdip_BrushCreateSolid(ARGB=0xff000000)
  1889. {
  1890. DllCall("gdiplus\GdipCreateSolidFill", "int", ARGB, "uint*", pBrush)
  1891. return pBrush
  1892. }
  1893.  
  1894. ;#####################################################################################
  1895.  
  1896. ; HatchStyleHorizontal = 0
  1897. ; HatchStyleVertical = 1
  1898. ; HatchStyleForwardDiagonal = 2
  1899. ; HatchStyleBackwardDiagonal = 3
  1900. ; HatchStyleCross = 4
  1901. ; HatchStyleDiagonalCross = 5
  1902. ; HatchStyle05Percent = 6
  1903. ; HatchStyle10Percent = 7
  1904. ; HatchStyle20Percent = 8
  1905. ; HatchStyle25Percent = 9
  1906. ; HatchStyle30Percent = 10
  1907. ; HatchStyle40Percent = 11
  1908. ; HatchStyle50Percent = 12
  1909. ; HatchStyle60Percent = 13
  1910. ; HatchStyle70Percent = 14
  1911. ; HatchStyle75Percent = 15
  1912. ; HatchStyle80Percent = 16
  1913. ; HatchStyle90Percent = 17
  1914. ; HatchStyleLightDownwardDiagonal = 18
  1915. ; HatchStyleLightUpwardDiagonal = 19
  1916. ; HatchStyleDarkDownwardDiagonal = 20
  1917. ; HatchStyleDarkUpwardDiagonal = 21
  1918. ; HatchStyleWideDownwardDiagonal = 22
  1919. ; HatchStyleWideUpwardDiagonal = 23
  1920. ; HatchStyleLightVertical = 24
  1921. ; HatchStyleLightHorizontal = 25
  1922. ; HatchStyleNarrowVertical = 26
  1923. ; HatchStyleNarrowHorizontal = 27
  1924. ; HatchStyleDarkVertical = 28
  1925. ; HatchStyleDarkHorizontal = 29
  1926. ; HatchStyleDashedDownwardDiagonal = 30
  1927. ; HatchStyleDashedUpwardDiagonal = 31
  1928. ; HatchStyleDashedHorizontal = 32
  1929. ; HatchStyleDashedVertical = 33
  1930. ; HatchStyleSmallConfetti = 34
  1931. ; HatchStyleLargeConfetti = 35
  1932. ; HatchStyleZigZag = 36
  1933. ; HatchStyleWave = 37
  1934. ; HatchStyleDiagonalBrick = 38
  1935. ; HatchStyleHorizontalBrick = 39
  1936. ; HatchStyleWeave = 40
  1937. ; HatchStylePlaid = 41
  1938. ; HatchStyleDivot = 42
  1939. ; HatchStyleDottedGrid = 43
  1940. ; HatchStyleDottedDiamond = 44
  1941. ; HatchStyleShingle = 45
  1942. ; HatchStyleTrellis = 46
  1943. ; HatchStyleSphere = 47
  1944. ; HatchStyleSmallGrid = 48
  1945. ; HatchStyleSmallCheckerBoard = 49
  1946. ; HatchStyleLargeCheckerBoard = 50
  1947. ; HatchStyleOutlinedDiamond = 51
  1948. ; HatchStyleSolidDiamond = 52
  1949. ; HatchStyleTotal = 53
  1950. Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
  1951. {
  1952. DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "int", ARGBfront, "int", ARGBback, "uint*", pBrush)
  1953. return pBrush
  1954. }
  1955.  
  1956. ;#####################################################################################
  1957.  
  1958. Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
  1959. {
  1960. if !(w && h)
  1961. DllCall("gdiplus\GdipCreateTexture", "uint", pBitmap, "int", WrapMode, "uint*", pBrush)
  1962. else
  1963. DllCall("gdiplus\GdipCreateTexture2", "uint", pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, "uint*", pBrush)
  1964. return pBrush
  1965. }
  1966.  
  1967. ;#####################################################################################
  1968.  
  1969. ; WrapModeTile = 0
  1970. ; WrapModeTileFlipX = 1
  1971. ; WrapModeTileFlipY = 2
  1972. ; WrapModeTileFlipXY = 3
  1973. ; WrapModeClamp = 4
  1974. Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
  1975. {
  1976. CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2)
  1977. DllCall("gdiplus\GdipCreateLineBrush", "uint", &PointF1, "uint", &PointF2, "int", ARGB1, "int", ARGB2, "int", WrapMode, "uint*", LGpBrush)
  1978. return LGpBrush
  1979. }
  1980.  
  1981. ;#####################################################################################
  1982.  
  1983. ; LinearGradientModeHorizontal = 0
  1984. ; LinearGradientModeVertical = 1
  1985. ; LinearGradientModeForwardDiagonal = 2
  1986. ; LinearGradientModeBackwardDiagonal = 3
  1987. Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
  1988. {
  1989. CreateRectF(RectF, x, y, w, h)
  1990. DllCall("gdiplus\GdipCreateLineBrushFromRect", "uint", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, "uint*", LGpBrush)
  1991. return LGpBrush
  1992. }
  1993.  
  1994. ;#####################################################################################
  1995.  
  1996. Gdip_CloneBrush(pBrush)
  1997. {
  1998. DllCall("gdiplus\GdipCloneBrush", "uint", pBrush, "uint*", pBrushClone)
  1999. return pBrushClone
  2000. }
  2001.  
  2002. ;#####################################################################################
  2003. ; Delete resources
  2004. ;#####################################################################################
  2005.  
  2006. Gdip_DeletePen(pPen)
  2007. {
  2008. return DllCall("gdiplus\GdipDeletePen", "uint", pPen)
  2009. }
  2010.  
  2011. ;#####################################################################################
  2012.  
  2013. Gdip_DeleteBrush(pBrush)
  2014. {
  2015. return DllCall("gdiplus\GdipDeleteBrush", "uint", pBrush)
  2016. }
  2017.  
  2018. ;#####################################################################################
  2019.  
  2020. Gdip_DisposeImage(pBitmap)
  2021. {
  2022. return DllCall("gdiplus\GdipDisposeImage", "uint", pBitmap)
  2023. }
  2024.  
  2025. ;#####################################################################################
  2026.  
  2027. Gdip_DeleteGraphics(pGraphics)
  2028. {
  2029. return DllCall("gdiplus\GdipDeleteGraphics", "uint", pGraphics)
  2030. }
  2031.  
  2032. ;#####################################################################################
  2033.  
  2034. Gdip_DisposeImageAttributes(ImageAttr)
  2035. {
  2036. return DllCall("gdiplus\GdipDisposeImageAttributes", "uint", ImageAttr)
  2037. }
  2038.  
  2039. ;#####################################################################################
  2040.  
  2041. Gdip_DeleteFont(hFont)
  2042. {
  2043. return DllCall("gdiplus\GdipDeleteFont", "uint", hFont)
  2044. }
  2045.  
  2046. ;#####################################################################################
  2047.  
  2048. Gdip_DeleteStringFormat(hFormat)
  2049. {
  2050. return DllCall("gdiplus\GdipDeleteStringFormat", "uint", hFormat)
  2051. }
  2052.  
  2053. ;#####################################################################################
  2054.  
  2055. Gdip_DeleteFontFamily(hFamily)
  2056. {
  2057. return DllCall("gdiplus\GdipDeleteFontFamily", "uint", hFamily)
  2058. }
  2059.  
  2060. ;#####################################################################################
  2061.  
  2062. Gdip_DeleteMatrix(Matrix)
  2063. {
  2064. return DllCall("gdiplus\GdipDeleteMatrix", "uint", Matrix)
  2065. }
  2066.  
  2067. ;#####################################################################################
  2068. ; Text functions
  2069. ;#####################################################################################
  2070.  
  2071. Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
  2072. {
  2073. IWidth := Width, IHeight:= Height
  2074.  
  2075. RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
  2076. RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
  2077. RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
  2078. RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
  2079. RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour)
  2080. RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
  2081. RegExMatch(Options, "i)NoWrap", NoWrap)
  2082. RegExMatch(Options, "i)R(\d)", Rendering)
  2083. RegExMatch(Options, "i)S(\d+)(p*)", Size)
  2084.  
  2085. if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
  2086. PassBrush := 1, pBrush := Colour2
  2087.  
  2088. if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
  2089. return -1
  2090.  
  2091. Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
  2092. Loop, Parse, Styles, |
  2093. {
  2094. if RegExMatch(Options, "\b" A_loopField)
  2095. Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
  2096. }
  2097.  
  2098. Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
  2099. Loop, Parse, Alignments, |
  2100. {
  2101. if RegExMatch(Options, "\b" A_loopField)
  2102. Align |= A_Index//2.1 ; 0|0|1|1|2|2
  2103. }
  2104.  
  2105. xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
  2106. ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
  2107. Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
  2108. Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
  2109. if !PassBrush
  2110. Colour := "0x" (Colour2 ? Colour2 : "ff000000")
  2111. Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
  2112. Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
  2113.  
  2114. hFamily := Gdip_FontFamilyCreate(Font)
  2115. hFont := Gdip_FontCreate(hFamily, Size, Style)
  2116. FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
  2117. hFormat := Gdip_StringFormatCreate(FormatStyle)
  2118. pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
  2119. if !(hFamily && hFont && hFormat && pBrush && pGraphics)
  2120. return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
  2121.  
  2122. CreateRectF(RC, xpos, ypos, Width, Height)
  2123. Gdip_SetStringFormatAlign(hFormat, Align)
  2124. Gdip_SetTextRenderingHint(pGraphics, Rendering)
  2125. ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2126.  
  2127. if vPos
  2128. {
  2129. StringSplit, ReturnRC, ReturnRC, |
  2130.  
  2131. if (vPos = "vCentre") || (vPos = "vCenter")
  2132. ypos += (Height-ReturnRC4)//2
  2133. else if (vPos = "Top") || (vPos = "Up")
  2134. ypos := 0
  2135. else if (vPos = "Bottom") || (vPos = "Down")
  2136. ypos := Height-ReturnRC4
  2137.  
  2138. CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
  2139. ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2140. }
  2141.  
  2142. if !Measure
  2143. E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
  2144.  
  2145. if !PassBrush
  2146. Gdip_DeleteBrush(pBrush)
  2147. Gdip_DeleteStringFormat(hFormat)
  2148. Gdip_DeleteFont(hFont)
  2149. Gdip_DeleteFontFamily(hFamily)
  2150. return E ? E : ReturnRC
  2151. }
  2152.  
  2153. ;#####################################################################################
  2154.  
  2155. Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
  2156. {
  2157. if !A_IsUnicode
  2158. {
  2159. nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", 0, "int", 0)
  2160. VarSetCapacity(wString, nSize*2)
  2161. DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", &wString, "int", nSize)
  2162. return DllCall("gdiplus\GdipDrawString", "uint", pGraphics
  2163. , "uint", &wString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", pBrush)
  2164. }
  2165. else
  2166. {
  2167. return DllCall("gdiplus\GdipDrawString", "uint", pGraphics
  2168. , "uint", &sString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", pBrush)
  2169. }
  2170. }
  2171.  
  2172. ;#####################################################################################
  2173.  
  2174. Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
  2175. {
  2176. VarSetCapacity(RC, 16)
  2177. if !A_IsUnicode
  2178. {
  2179. nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", 0, "int", 0)
  2180. VarSetCapacity(wString, nSize*2)
  2181. DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", &wString, "int", nSize)
  2182. DllCall("gdiplus\GdipMeasureString", "uint", pGraphics
  2183. , "uint", &wString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", &RC, "uint*", Chars, "uint*", Lines)
  2184. }
  2185. else
  2186. {
  2187. DllCall("gdiplus\GdipMeasureString", "uint", pGraphics
  2188. , "uint", &sString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", &RC, "uint*", Chars, "uint*", Lines)
  2189. }
  2190. return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
  2191. }
  2192.  
  2193. ; Near = 0
  2194. ; Center = 1
  2195. ; Far = 2
  2196. Gdip_SetStringFormatAlign(hFormat, Align)
  2197. {
  2198. return DllCall("gdiplus\GdipSetStringFormatAlign", "uint", hFormat, "int", Align)
  2199. }
  2200.  
  2201. ; StringFormatFlagsDirectionRightToLeft = 0x00000001
  2202. ; StringFormatFlagsDirectionVertical = 0x00000002
  2203. ; StringFormatFlagsNoFitBlackBox = 0x00000004
  2204. ; StringFormatFlagsDisplayFormatControl = 0x00000020
  2205. ; StringFormatFlagsNoFontFallback = 0x00000400
  2206. ; StringFormatFlagsMeasureTrailingSpaces = 0x00000800
  2207. ; StringFormatFlagsNoWrap = 0x00001000
  2208. ; StringFormatFlagsLineLimit = 0x00002000
  2209. ; StringFormatFlagsNoClip = 0x00004000
  2210. Gdip_StringFormatCreate(Format=0, Lang=0)
  2211. {
  2212. DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, "uint*", hFormat)
  2213. return hFormat
  2214. }
  2215.  
  2216. ; Regular = 0
  2217. ; Bold = 1
  2218. ; Italic = 2
  2219. ; BoldItalic = 3
  2220. ; Underline = 4
  2221. ; Strikeout = 8
  2222. Gdip_FontCreate(hFamily, Size, Style=0)
  2223. {
  2224. DllCall("gdiplus\GdipCreateFont", "uint", hFamily, "float", Size, "int", Style, "int", 0, "uint*", hFont)
  2225. return hFont
  2226. }
  2227.  
  2228. Gdip_FontFamilyCreate(Font)
  2229. {
  2230. if !A_IsUnicode
  2231. {
  2232. nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &Font, "int", -1, "uint", 0, "int", 0)
  2233. VarSetCapacity(wFont, nSize*2)
  2234. DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &Font, "int", -1, "uint", &wFont, "int", nSize)
  2235. DllCall("gdiplus\GdipCreateFontFamilyFromName", "uint", &wFont, "uint", 0, "uint*", hFamily)
  2236. }
  2237. else
  2238. DllCall("gdiplus\GdipCreateFontFamilyFromName", "uint", &Font, "uint", 0, "uint*", hFamily)
  2239. return hFamily
  2240. }
  2241.  
  2242. ;#####################################################################################
  2243. ; Matrix functions
  2244. ;#####################################################################################
  2245.  
  2246. Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
  2247. {
  2248. DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, "uint*", Matrix)
  2249. return Matrix
  2250. }
  2251.  
  2252. Gdip_CreateMatrix()
  2253. {
  2254. DllCall("gdiplus\GdipCreateMatrix", "uint*", Matrix)
  2255. return Matrix
  2256. }
  2257.  
  2258. ;#####################################################################################
  2259. ; GraphicsPath functions
  2260. ;#####################################################################################
  2261.  
  2262. ; Alternate = 0
  2263. ; Winding = 1
  2264. Gdip_CreatePath(BrushMode=0)
  2265. {
  2266. DllCall("gdiplus\GdipCreatePath", "int", BrushMode, "uint*", Path)
  2267. return Path
  2268. }
  2269.  
  2270. Gdip_AddPathEllipse(Path, x, y, w, h)
  2271. {
  2272. return DllCall("gdiplus\GdipAddPathEllipse", "uint", Path, "float", x, "float", y, "float", w, "float", h)
  2273. }
  2274.  
  2275. Gdip_AddPathPolygon(Path, Points)
  2276. {
  2277. StringSplit, Points, Points, |
  2278. VarSetCapacity(PointF, 8*Points0)
  2279. Loop, %Points0%
  2280. {
  2281. StringSplit, Coord, Points%A_Index%, `,
  2282. NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  2283. }
  2284.  
  2285. return DllCall("gdiplus\GdipAddPathPolygon", "uint", Path, "uint", &PointF, "int", Points0)
  2286. }
  2287.  
  2288. Gdip_DeletePath(Path)
  2289. {
  2290. return DllCall("gdiplus\GdipDeletePath", "uint", Path)
  2291. }
  2292.  
  2293. ;#####################################################################################
  2294. ; Quality functions
  2295. ;#####################################################################################
  2296.  
  2297. ; SystemDefault = 0
  2298. ; SingleBitPerPixelGridFit = 1
  2299. ; SingleBitPerPixel = 2
  2300. ; AntiAliasGridFit = 3
  2301. ; AntiAlias = 4
  2302. Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
  2303. {
  2304. return DllCall("gdiplus\GdipSetTextRenderingHint", "uint", pGraphics, "int", RenderingHint)
  2305. }
  2306.  
  2307. ; Default = 0
  2308. ; LowQuality = 1
  2309. ; HighQuality = 2
  2310. ; Bilinear = 3
  2311. ; Bicubic = 4
  2312. ; NearestNeighbor = 5
  2313. ; HighQualityBilinear = 6
  2314. ; HighQualityBicubic = 7
  2315. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  2316. {
  2317. return DllCall("gdiplus\GdipSetInterpolationMode", "uint", pGraphics, "int", InterpolationMode)
  2318. }
  2319.  
  2320. ; Default = 0
  2321. ; HighSpeed = 1
  2322. ; HighQuality = 2
  2323. ; None = 3
  2324. ; AntiAlias = 4
  2325. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  2326. {
  2327. return DllCall("gdiplus\GdipSetSmoothingMode", "uint", pGraphics, "int", SmoothingMode)
  2328. }
  2329.  
  2330. ; CompositingModeSourceOver = 0 (blended)
  2331. ; CompositingModeSourceCopy = 1 (overwrite)
  2332. Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
  2333. {
  2334. return DllCall("gdiplus\GdipSetCompositingMode", "uint", pGraphics, "int", CompositingMode)
  2335. }
  2336.  
  2337. ;#####################################################################################
  2338. ; Extra functions
  2339. ;#####################################################################################
  2340.  
  2341. Gdip_Startup()
  2342. {
  2343. if !DllCall("GetModuleHandle", "str", "gdiplus")
  2344. DllCall("LoadLibrary", "str", "gdiplus")
  2345. VarSetCapacity(si, 16, 0), si := Chr(1)
  2346. DllCall("gdiplus\GdiplusStartup", "uint*", pToken, "uint", &si, "uint", 0)
  2347. return pToken
  2348. }
  2349.  
  2350. Gdip_Shutdown(pToken)
  2351. {
  2352. DllCall("gdiplus\GdiplusShutdown", "uint", pToken)
  2353. if hModule := DllCall("GetModuleHandle", "str", "gdiplus")
  2354. DllCall("FreeLibrary", "uint", hModule)
  2355. return 0
  2356. }
  2357.  
  2358. ; Prepend = 0; The new operation is applied before the old operation.
  2359. ; Append = 1; The new operation is applied after the old operation.
  2360. Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
  2361. {
  2362. return DllCall("gdiplus\GdipRotateWorldTransform", "uint", pGraphics, "float", Angle, "int", MatrixOrder)
  2363. }
  2364.  
  2365. Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2366. {
  2367. return DllCall("gdiplus\GdipScaleWorldTransform", "uint", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2368. }
  2369.  
  2370. Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2371. {
  2372. return DllCall("gdiplus\GdipTranslateWorldTransform", "uint", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2373. }
  2374.  
  2375. Gdip_ResetWorldTransform(pGraphics)
  2376. {
  2377. return DllCall("gdiplus\GdipResetWorldTransform", "uint", pGraphics)
  2378. }
  2379.  
  2380. Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
  2381. {
  2382. pi := 3.14159, TAngle := Angle*(pi/180)
  2383.  
  2384. Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
  2385. if ((Bound >= 0) && (Bound <= 90))
  2386. xTranslation := Height*Sin(TAngle), yTranslation := 0
  2387. else if ((Bound > 90) && (Bound <= 180))
  2388. xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
  2389. else if ((Bound > 180) && (Bound <= 270))
  2390. xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
  2391. else if ((Bound > 270) && (Bound <= 360))
  2392. xTranslation := 0, yTranslation := -Width*Sin(TAngle)
  2393. }
  2394.  
  2395. Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
  2396. {
  2397. pi := 3.14159, TAngle := Angle*(pi/180)
  2398. if !(Width && Height)
  2399. return -1
  2400. RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
  2401. RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
  2402. }
  2403.  
  2404. ; RotateNoneFlipNone = 0
  2405. ; Rotate90FlipNone = 1
  2406. ; Rotate180FlipNone = 2
  2407. ; Rotate270FlipNone = 3
  2408. ; RotateNoneFlipX = 4
  2409. ; Rotate90FlipX = 5
  2410. ; Rotate180FlipX = 6
  2411. ; Rotate270FlipX = 7
  2412. ; RotateNoneFlipY = Rotate180FlipX
  2413. ; Rotate90FlipY = Rotate270FlipX
  2414. ; Rotate180FlipY = RotateNoneFlipX
  2415. ; Rotate270FlipY = Rotate90FlipX
  2416. ; RotateNoneFlipXY = Rotate180FlipNone
  2417. ; Rotate90FlipXY = Rotate270FlipNone
  2418. ; Rotate180FlipXY = RotateNoneFlipNone
  2419. ; Rotate270FlipXY = Rotate90FlipNone
  2420.  
  2421. Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1)
  2422. {
  2423. return DllCall("gdiplus\GdipImageRotateFlip", "uint", pBitmap, "int", RotateFlipType)
  2424. }
  2425.  
  2426. ; Replace = 0
  2427. ; Intersect = 1
  2428. ; Union = 2
  2429. ; Xor = 3
  2430. ; Exclude = 4
  2431. ; Complement = 5
  2432. Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
  2433. {
  2434. return DllCall("gdiplus\GdipSetClipRect", "uint", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
  2435. }
  2436.  
  2437. Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
  2438. {
  2439. return DllCall("gdiplus\GdipSetClipPath", "uint", pGraphics, "uint", Path, "int", CombineMode)
  2440. }
  2441.  
  2442. Gdip_ResetClip(pGraphics)
  2443. {
  2444. return DllCall("gdiplus\GdipResetClip", "uint", pGraphics)
  2445. }
  2446.  
  2447. Gdip_GetClipRegion(pGraphics)
  2448. {
  2449. Region := Gdip_CreateRegion()
  2450. DllCall("gdiplus\GdipGetClip", "uint" pGraphics, "uint*", Region)
  2451. return Region
  2452. }
  2453.  
  2454. Gdip_SetClipRegion(pGraphics, Region, CombineMode=0)
  2455. {
  2456. return DllCall("gdiplus\GdipSetClipRegion", "uint", pGraphics, "uint", Region, "int", CombineMode)
  2457. }
  2458.  
  2459. Gdip_CreateRegion()
  2460. {
  2461. DllCall("gdiplus\GdipCreateRegion", "uint*", Region)
  2462. return Region
  2463. }
  2464.  
  2465. Gdip_DeleteRegion(Region)
  2466. {
  2467. return DllCall("gdiplus\GdipDeleteRegion", "uint", Region)
  2468. }
  2469.  
  2470. ;#####################################################################################
  2471. ; BitmapLockBits
  2472. ;#####################################################################################
  2473.  
  2474. Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a)
  2475. {
  2476. CreateRect(Rect, x, y, w, h)
  2477. VarSetCapacity(BitmapData, 21, 0)
  2478. E := DllCall("Gdiplus\GdipBitmapLockBits", "uint", pBitmap, "uint", &Rect, "uint", LockMode, "int", PixelFormat, "uint", &BitmapData)
  2479. Stride := NumGet(BitmapData, 8)
  2480. Scan0 := NumGet(BitmapData, 16)
  2481. return E
  2482. }
  2483.  
  2484. ;#####################################################################################
  2485.  
  2486. Gdip_UnlockBits(pBitmap, ByRef BitmapData)
  2487. {
  2488. return DllCall("Gdiplus\GdipBitmapUnlockBits", "uint", pBitmap, "uint", &BitmapData)
  2489. }
  2490.  
  2491. ;#####################################################################################
  2492.  
  2493. Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride)
  2494. {
  2495. Numput(ARGB, Scan0+0, (x*4)+(y*Stride))
  2496. }
  2497.  
  2498. ;#####################################################################################
  2499.  
  2500. Gdip_GetLockBitPixel(Scan0, x, y, Stride)
  2501. {
  2502. return NumGet(Scan0+0, (x*4)+(y*Stride))
  2503. }
  2504.  
  2505. ;#####################################################################################
  2506.  
  2507. Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize)
  2508. {
  2509. static PixelateBitmap
  2510. if !PixelateBitmap
  2511. {
  2512. MCode_PixelateBitmap := "83EC388B4424485355568B74245C99F7FE8B5C244C8B6C2448578BF88BCA894C241C897C243485FF0F8E2E0300008B44245"
  2513. . "499F7FE897C24448944242833C089542418894424308944242CEB038D490033FF397C2428897C24380F8E750100008BCE0FAFCE894C24408DA4240000"
  2514. . "000033C03BF08944241089442460894424580F8E8A0000008B5C242C8D4D028BD52BD183C203895424208D3CBB0FAFFE8BD52BD142895424248BD52BD"
  2515. . "103F9897C24148974243C8BCF8BFE8DA424000000008B5C24200FB61C0B03C30FB619015C24588B5C24240FB61C0B015C24600FB61C11015C241083C1"
  2516. . "0483EF0175D38B7C2414037C245C836C243C01897C241475B58B7C24388B6C244C8B5C24508B4C244099F7F9894424148B44245899F7F9894424588B4"
  2517. . "4246099F7F9894424608B44241099F7F98944241085F60F8E820000008D4B028BC32BC18D68038B44242C8D04B80FAFC68BD32BD142895424248BD32B"
  2518. . "D103C18944243C89742420EB038D49008BC88BFE0FB64424148B5C24248804290FB644245888010FB644246088040B0FB644241088040A83C10483EF0"
  2519. . "175D58B44243C0344245C836C2420018944243C75BE8B4C24408B5C24508B6C244C8B7C2438473B7C2428897C24380F8C9FFEFFFF8B4C241C33D23954"
  2520. . "24180F846401000033C03BF2895424108954246089542458895424148944243C0F8E82000000EB0233D2395424187E6F8B4C243003C80FAF4C245C8B4"
  2521. . "424280FAFC68D550203CA8D0C818BC52BC283C003894424208BC52BC2408BFD2BFA8B54241889442424895424408B4424200FB614080FB60101542414"
  2522. . "8B542424014424580FB6040A0FB61439014424600154241083C104836C24400175CF8B44243C403BC68944243C7C808B4C24188B4424140FAFCE99F7F"
  2523. . "9894424148B44245899F7F9894424588B44246099F7F9894424608B44241099F7F98944241033C08944243C85F60F8E7F000000837C2418007E6F8B4C"
  2524. . "243003C80FAF4C245C8B4424280FAFC68D530203CA8D0C818BC32BC283C003894424208BC32BC2408BFB2BFA8B54241889442424895424400FB644241"
  2525. . "48B5424208804110FB64424580FB654246088018B4424248814010FB654241088143983C104836C24400175CF8B44243C403BC68944243C7C818B4C24"
  2526. . "1C8B44245C0144242C01742430836C2444010F85F4FCFFFF8B44245499F7FE895424188944242885C00F8E890100008BF90FAFFE33D2897C243C89542"
  2527. . "45489442438EB0233D233C03BCA89542410895424608954245889542414894424400F8E840000003BF27E738B4C24340FAFCE03C80FAF4C245C034C24"
  2528. . "548D55028BC52BC283C003894424208BC52BC2408BFD03CA894424242BFA89742444908B5424200FB6040A0FB611014424148B442424015424580FB61"
  2529. . "4080FB6040F015424600144241083C104836C24440175CF8B4424408B7C243C8B4C241C33D2403BC1894424400F8C7CFFFFFF8B44241499F7FF894424"
  2530. . "148B44245899F7FF894424588B44246099F7FF894424608B44241099F7FF8944241033C08944244085C90F8E8000000085F67E738B4C24340FAFCE03C"
  2531. . "80FAF4C245C034C24548D53028BC32BC283C003894424208BC32BC2408BFB03CA894424242BFA897424448D49000FB65424148B4424208814010FB654"
  2532. . "24580FB644246088118B5424248804110FB644241088043983C104836C24440175CF8B4424408B7C243C8B4C241C403BC1894424407C808D04B500000"
  2533. . "00001442454836C2438010F858CFEFFFF33D233C03BCA89542410895424608954245889542414894424440F8E9A000000EB048BFF33D2395424180F8E"
  2534. . "7D0000008B4C24340FAFCE03C80FAF4C245C8B4424280FAFC68D550203CA8D0C818BC52BC283C003894424208BC52BC240894424248BC52BC28B54241"
  2535. . "8895424548DA424000000008B5424200FB6140A015424140FB611015424588B5424240FB6140A015424600FB614010154241083C104836C24540175CF"
  2536. . "8B4424448B4C241C403BC1894424440F8C6AFFFFFF0FAF4C24188B44241499F7F9894424148B44245899F7F9894424588B44246099F7F9894424608B4"
  2537. . "4241099F7F98944241033C03944241C894424540F8E7B0000008B7C241885FF7E688B4C24340FAFCE03C80FAF4C245C8B4424280FAFC68D530203CA8D"
  2538. . "0C818BC32BC283C003894424208BC32BC2408BEB894424242BEA0FB65424148B4424208814010FB65424580FB644246088118B5424248804110FB6442"
  2539. . "41088042983C10483EF0175D18B442454403B44241C894424547C855F5E5D33C05B83C438C3"
  2540. VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2)
  2541. Loop % StrLen(MCode_PixelateBitmap)//2 ;%
  2542. NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "char")
  2543. }
  2544.  
  2545. Gdip_GetImageDimensions(pBitmap, Width, Height)
  2546. if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
  2547. return -1
  2548. if (BlockSize > Width || BlockSize > Height)
  2549. return -2
  2550.  
  2551. E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
  2552. E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
  2553. if (E1 || E2)
  2554. return -3
  2555.  
  2556. E := DllCall(&PixelateBitmap, "uint", Scan01, "uint", Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize)
  2557. Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
  2558. return 0
  2559. }
  2560.  
  2561. ;#####################################################################################
  2562.  
  2563. Gdip_ToARGB(A, R, G, B)
  2564. {
  2565. return (A << 24) | (R << 16) | (G << 8) | B
  2566. }
  2567.  
  2568. ;#####################################################################################
  2569.  
  2570. Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B)
  2571. {
  2572. A := (0xff000000 & ARGB) >> 24
  2573. R := (0x00ff0000 & ARGB) >> 16
  2574. G := (0x0000ff00 & ARGB) >> 8
  2575. B := 0x000000ff & ARGB
  2576. }
  2577.  
  2578. ;#####################################################################################
  2579.  
  2580. Gdip_AFromARGB(ARGB)
  2581. {
  2582. return (0xff000000 & ARGB) >> 24
  2583. }
  2584.  
  2585. ;#####################################################################################
  2586.  
  2587. Gdip_RFromARGB(ARGB)
  2588. {
  2589. return (0x00ff0000 & ARGB) >> 16
  2590. }
  2591.  
  2592. ;#####################################################################################
  2593.  
  2594. Gdip_GFromARGB(ARGB)
  2595. {
  2596. return (0x0000ff00 & ARGB) >> 8
  2597. }
  2598.  
  2599. ;#####################################################################################
  2600.  
  2601. Gdip_BFromARGB(ARGB)
  2602. {
  2603. return 0x000000ff & ARGB
  2604. }
  2605.  
  2606.  
  2607.  
  2608.  
  2609.  
  2610. ;_____________________________________________________________
  2611. ;End of Program
  2612. ; \ /
  2613. ; Made By /\(^_^)/\
  2614. ; Bugz000 .--( | )--.
  2615. ; _/\ | /\_
  2616. ; `v`
  2617. ;terrible ASCII art but i dont think you look pretty either okay?
  2618. ;Credits to tic for GDIP
  2619. ;Credits to tidbit for being tidbit
  2620. ;Credits to Talisman for being there when times got tough during the creation of this program, we did it bro
  2621. ;we cried for hours but we did it in the end...
Add Comment
Please, Sign In to add comment