Gdip.ahk 84 KB

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