Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #SingleInstance, Force ; Allow only one running instance, relaunches on new instance.
- #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
- SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
- OnExit("ExitFunc")
- pToken := Gdip_Startup()
- Gdip_9Scale(A_Desktop "\9Scale.png", 500, 500, 5)
- Return
- Gdip_9Scale(_InputFile, _NewW, _NewH, _X1, _Y1:="", _X2:="", _Y2:="") {
- Static
- If (_Y1 = "")
- _Y1 := _X1
- If (_X2 = "")
- _X2 := _X1
- If (_Y2 = "")
- _Y2 := _Y1
- ; Input file
- pBitmapIn := Gdip_CreateBitmapFromFile(_InputFile)
- _imgW := Gdip_GetImageWidth(pBitmapIn)
- _imgH := Gdip_GetImageHeight(pBitmapIn)
- If (_X1 + _X2 >= _imgW) OR (_Y1 + _Y2 >= _imgH) {
- MsgBox, Too big.
- Goto, Cleanup
- }
- ; Split image into 9 parts:
- ; 1 2 3
- ; 4 5 6
- ; 7 8 9
- _W1 := _imgW - (_X1 + _X2)
- _W2 := _imgW - _X2
- _H1 := _imgH - (_Y1 + _Y2)
- _H2 := _imgH - _Y2
- pBitmap1 := Gdip_CloneBitmapArea(pBitmapIn , 0 , 0 , _X1 , _Y1)
- pBitmap2 := Gdip_CloneBitmapArea(pBitmapIn , _X1 , 0 , _W1 , _Y1)
- pBitmap3 := Gdip_CloneBitmapArea(pBitmapIn , _W2 , 0 , _X2 , _Y1)
- pBitmap4 := Gdip_CloneBitmapArea(pBitmapIn , 0 , _Y1 , _X1 , _H1)
- pBitmap5 := Gdip_CloneBitmapArea(pBitmapIn , _X1 , _Y1 , _W1 , _H1)
- pBitmap6 := Gdip_CloneBitmapArea(pBitmapIn , _W2 , _Y1 , _X2 , _H1)
- pBitmap7 := Gdip_CloneBitmapArea(pBitmapIn , 0 , _H2 , _X1 , _Y2)
- pBitmap8 := Gdip_CloneBitmapArea(pBitmapIn , _X1 , _H2 , _W1 , _Y2)
- pBitmap9 := Gdip_CloneBitmapArea(pBitmapIn , _W2 , _H2 , _X2 , _Y2)
- ; Draw the output file
- _CW := _NewW - (_X1 + _X2)
- _CH := _NewH - (_Y1 + _Y2)
- pBitmapOut := Gdip_CreateBitmap(_NewW, _NewH)
- gBitmapOut := Gdip_GraphicsFromImage(pBitmapOut)
- Gdip_SetInterpolationMode(gBitmapOut, 5)
- Gdip_SetSmoothingMode(gBitmapOut, 3)
- gdip_DrawImage(gBitmapOut, pBitmap1 , 0 , 0 , _X1 , _Y1)
- gdip_DrawImage(gBitmapOut, pBitmap2 , _X1 , 0 , _CW , _Y1) ; This line X
- gdip_DrawImage(gBitmapOut, pBitmap3 , _X1 + _CW , 0 , _X2 , _Y1)
- gdip_DrawImage(gBitmapOut, pBitmap4 , 0 , _Y1 , _X1 , _CH) ; This line Y
- gdip_DrawImage(gBitmapOut, pBitmap5 , _X1 , _Y1 , _CW , _CH) ; This line X, Y
- gdip_DrawImage(gBitmapOut, pBitmap6 , _X1 + _CW , _Y1 , _X2 , _CH) ; This line Y
- gdip_DrawImage(gBitmapOut, pBitmap7 , 0 , _Y1 + _CH , _X1 , _Y2)
- gdip_DrawImage(gBitmapOut, pBitmap8 , _X1 , _Y1 + _CH , _CW , _Y2) ; This line X
- gdip_DrawImage(gBitmapOut, pBitmap9 , _X1 + _CW , _Y1 + _CH , _X2 , _Y2)
- Gui, -MinimizeBox -MaximizeBox +LastFound
- Gui, Add, Picture, 0xE vpNew x0 y0 w%_NewW% h%_NewH%
- GuiControlGet, hwndpNew, hwnd, pNew
- hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmapOut) ; Convert Pointer to Handle
- SetImage(hwndpNew, hBitmap) ; Set tool handle as image in GUI
- Gdip_DisposeImage(hBitmap)
- Gui, Show, x360 y240 w%_NewW% h%_NewH%
- Cleanup:
- ; Delete Resources
- Gdip_DisposeImage(pBitmapIn)
- Gdip_DisposeImage(pBitmap1)
- Gdip_DisposeImage(pBitmap2)
- Gdip_DisposeImage(pBitmap3)
- Gdip_DisposeImage(pBitmap4)
- Gdip_DisposeImage(pBitmap5)
- Gdip_DisposeImage(pBitmap6)
- Gdip_DisposeImage(pBitmap7)
- Gdip_DisposeImage(pBitmap8)
- Gdip_DisposeImage(pBitmap9)
- Gdip_DisposeImage(pBitmapOut)
- Gdip_DeleteGraphics(gBitmapOut)
- }
- GuiClose:
- ExitApp
- ExitFunc() {
- Global
- Gdip_Shutdown(pToken)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement