Advertisement
pastamaker

gdip & maths

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