Image2Include - #include images in your scripts

Post your working scripts, libraries and tools
guest3456
Posts: 3109
Joined: 09 Oct 2013, 10:31

Image2Include - #include images in your scripts

13 Nov 2019, 09:42

see @just me 's original script here:

https://autohotkey.com/board/topic/93292-image2include-include-images-in-your-scripts/

this allows you to choose an image file, and the script will convert the image into an encoded base64 hex string.. then you can include the function in your script and decode the string back to an image that you can use in your GUIs or in GDI+.

i've backported it to make the generated output script compatible with AHK Basic

changes:
https://github.com/mmikeww/image2include/commit/2226937342a11e2b82d6a186d8f1a0019c55e0e2

code here:
https://github.com/mmikeww/image2include

guest3456
Posts: 3109
Joined: 09 Oct 2013, 10:31

Re: Image2Include - #include images in your scripts

13 Nov 2019, 12:21

looks like swagfag already added this to the GDIP AHKv2 lib, based on the work here, so this is better for GDIP:

Code: Select all

GdipBitmapFromBase64(ByRef Base64)
{
   Ptr := A_PtrSize ? "Ptr" : "UInt"
   UPtr := A_PtrSize ? "UPtr" : "UInt"

   ; calculate the length of the buffer needed
   if !(DllCall("crypt32\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), Ptr, &Base64, "UInt", 0, "UInt", 0x01, Ptr, 0, "UIntP", DecLen, Ptr, 0, Ptr, 0))
      return -1

   VarSetCapacity(Dec, DecLen, 0)

   ; decode the Base64 encoded string
   if !(DllCall("crypt32\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), Ptr, &Base64, "UInt", 0, "UInt", 0x01, Ptr, &Dec, "UIntP", DecLen, Ptr, 0, Ptr, 0))
      return -2

   ; create a memory stream
   if !(pStream := DllCall("shlwapi\SHCreateMemStream", Ptr, &Dec, "UInt", DecLen, UPtr))
      return -3

   DllCall("gdiplus\GdipCreateBitmapFromStreamICM", Ptr, pStream, Ptr "P", pBitmap)

   PtrSize := A_PtrSize ? A_PtrSize : 4
   Release := NumGet( NumGet( pStream+0 ), 2*PtrSize)
   DllCall(Release, Ptr, pStream)

   return pBitmap
}
just use the image2include script to generate the base64 string and then the above code will work for all AHK versions to create the GDIP Bitmap

User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Image2Include - #include images in your scripts

13 Nov 2019, 13:54

@guest3456,

I'm currently using the functions below...

These are what I settled on after making that post in "Ask for Help" that you linked to: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=49849

Code: Select all

; GDI+ Startup
hGdip := DllCall("Kernel32.dll\LoadLibrary", "Str", "Gdiplus.dll") ; Load module
VarSetCapacity(GdiplusStartupInput, (A_PtrSize = 8 ? 24 : 16), 0) ; GdiplusStartupInput structure
NumPut(1, GdiplusStartupInput, 0, "UInt") ; GdiplusVersion
DllCall("Gdiplus.dll\GdiplusStartup", "PtrP", pToken, "Ptr", &GdiplusStartupInput, "Ptr", 0) ; Initialize GDI+

Code: Select all

; Clean up resources used by GDI+
DllCall("Gdiplus.dll\GdiplusShutdown", "Ptr", pToken)

Code: Select all

GdipCreateBitmapFromBase64(B64) {
	VarSetCapacity(B64Len, 0)
	DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", StrLen(B64), "UInt", 0x01, "Ptr", 0, "UIntP", B64Len, "Ptr", 0, "Ptr", 0)
	VarSetCapacity(B64Dec, B64Len, 0) ; pbBinary size
	DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", StrLen(B64), "UInt", 0x01, "Ptr", &B64Dec, "UIntP", B64Len, "Ptr", 0, "Ptr", 0)
	pStream := DllCall("Shlwapi.dll\SHCreateMemStream", "Ptr", &B64Dec, "UInt", B64Len, "UPtr")
	VarSetCapacity(pBitmap, 0)
	DllCall("Gdiplus.dll\GdipCreateBitmapFromStreamICM", "Ptr", pStream, "PtrP", pBitmap)
	ObjRelease(pStream)
	return pBitmap
}

Code: Select all

GdipCreateHBITMAPFromBitmap(pBitmap) {
	VarSetCapacity(hBitmap, 0)
	DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "UInt", pBitmap, "UInt*", hBitmap, "Int", 0XFFFFFFFF)
	return hBitmap
}

Code: Select all

GdipCreateHICONFromBitmap(pBitmap) {
	VarSetCapacity(hIcon, 0)
	DllCall("Gdiplus.dll\GdipCreateHICONFromBitmap", "Ptr", pBitmap, "PtrP", hIcon, "UInt", 0)
	return hIcon
}

Code: Select all

GdipCreateHBITMAPFromBase64(B64) {
	pBitmap := GdipCreateBitmapFromBase64(B64)
	return GdipCreateHBITMAPFromBitmap(pBitmap)
}

To use the image for a picture control, I use something like this:

Gui, Add, Picture, x0 y0 w16 h16 +BackgroundTrans, % "HBITMAP:*" GdipCreateHBITMAPFromBase64(VarOfBase64String)

I wanted to post these to show anyone interested how to use the image with a picture control.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
guest3456
Posts: 3109
Joined: 09 Oct 2013, 10:31

Re: Image2Include - #include images in your scripts

13 Nov 2019, 14:21

TheDewd wrote:
13 Nov 2019, 13:54
@guest3456,

I'm currently using the functions below...
yes, thanks, but my purpose of this was to make the func backward compatible with AHK Basic 1.0 which I originally did in the OP for the original script, and then modified the func swagfrag created based on your thread

User avatar
Hellbent
Posts: 1057
Joined: 23 Sep 2017, 13:34

Re: Image2Include - #include images in your scripts

13 Nov 2019, 21:50

Awesome stuff.
I had come to the assumption that this type of image converting was only suitable for small images almost a year ago.

In the long run I'm glad that I had that false assumption because it was one of the driving forces that made me create my bitmap maker which is better suited for creating images that can be altered and scaled, but it's nice to know that this can be done with larger images.

Will definitely come in handy.

Thanks.
dammtools
Posts: 12
Joined: 11 Oct 2015, 18:02

Re: Image2Include - #include images in your scripts

15 Nov 2019, 00:33

guest3456 wrote:
13 Nov 2019, 09:42
see @just me 's original script here:

https://autohotkey.com/board/topic/93292-image2include-include-images-in-your-scripts/

this allows you to choose an image file, and the script will convert the image into an encoded base64 hex string.. then you can include the function in your script and decode the string back to an image that you can use in your GUIs or in GDI+.

i've backported it to make the generated output script compatible with AHK Basic

changes:
https://github.com/mmikeww/image2include/commit/2226937342a11e2b82d6a186d8f1a0019c55e0e2

code here:
https://github.com/mmikeww/image2include
First of all, nice work so far.
Been trying to use your script, but I have no clue how to add more images in a GUI using this. Can you tell me how?
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Image2Include - #include images in your scripts

15 Nov 2019, 08:41

dammtools wrote:
15 Nov 2019, 00:33
First of all, nice work so far.
Been trying to use your script, but I have no clue how to add more images in a GUI using this. Can you tell me how?

This is using my older functions, because I already had the code ready to post.

Code: Select all

#SingleInstance, Force

B64Logo := "iVBORw0KGgoAAAANSUhEUgAAAgUAAABOCAMAAACHQpW5AAACxFBMVEVHcEwADhwAGTMACBE/V24AAAA/V24AKlVra2sAAAAAAABra2s/V3IAAAAAAABra2tra2sAAAAAChQ/VHM/P3k/V3Nr//8AAAA/X24/V24/V25r//9ra2sAAAA/VHA/V3Bra2s/VHI/XG4AAAI/WnNra2s/VG4AAABra2sAAABra2tra2sAEiQAAABra2tra2tra2tra2sAAAAADBcAIEAAAAAAAAAAAAAAFSoAAAkADRkABw8AAAAAAAAAAAAAAAAAAAAABgYAAAAAAAAAAAAAAAAAAAAAECDX2NmwsLHQ0NDAxcqys7PZ2dlaWlulpaXi4uJJSUo5OTlHR0fe398ABQu6urvi4+RcXF1MTU2qqqqPj5DX2NimpqZgYGAAAABFRUUAAAAAAAAAAAAAAAAAAAAAAACNjY0AAAA6OjoAAACvsLDQ1Nfm5+fm5+jj5OXDyM3d3d7DytHFxsjEx8rn6Ono6OiysrKfn5+rq6udnZ2lpaVfX2CioqKgoKBeXl+dnZ3p6uvr7O0/V3Dt7u/x8vPv8PHw8fP09ffV1dXMzMzHx8fT09Pz8/PDw8PFxcXb29u3t7e/v7/P0NHR0tLDxMXJycm9vb319vfPz8/R0dHz9PWNjY3l5ucAAACJiYny8/XV1tbl5eW5ubm1tbXd3t/s7e/BwcHn5+ft7e+xsbH39/eztLU8PDzr6+v19fezs7PZ2dnv7+/h4eG7u7utra3X19f5+vuvr687Ozzp6enj4+Pt7e33+Pnu7/H5+fmrq6vf39/j4+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yqWbbWQuUPh3r7CTK3LPqgsPKupnT0HlQJNSSEsnUdfuvvfXFmY2pVssBC6vgO54xvcDJYihhdkrsrnioBam4OTNFeTDraBWmx7XzLr9i1EkBrKIFyDMUyh7F3YCGhbpxO5im41pxBsjVpRmMm6rBgF99J8fVaTnf06DdxLma84GaUdGwM9SEabL+4eL9mYyfq1c8AD/gWuPm4dREKtVu3T+cEzgTNazOvPtzbntZgRCGtNRvT+mO9u+5zsPWIQrMVWqtiTEjTMXTpGeg/aEHZGrZ0ultfwR5W74w2kz786XaXSldquzh+DNzS11IwSL0vMKBUIzwz6c8S5Hz4ZMeQ2PFOoQN3SldaNdpp/Ta4pPHFp+arBg9tdGOVAUiWedHYhmbRxVwfexT8KKv6d9A1qb7Kx65EazaBQnbge8B5R8S9kBjit9g18Y+AlYqtFuv/V0QI19K+PeIttxIWthknNFMRVg7doFkRcjuqQ+DUnrrgfvEYwCdHS4/bibiTkhffY2Il0rW/4IV5Aj9ohJOTYCC9Sl4wybgjOmze4VXEy2g2vkpdsNPeHV/GfS5Z6hsLLBDwgC1uawev4W1w1rTvCG6VLS2q1C8E7FdoWTa5SpIP3Gr29OElqPK8UAK8W03Z7hjCKF92t4o2USAY4QycWKJA1pT/+kZIl+xtyZi7Dq87JEwAAAABJRU5ErkJggg=="

; GDI+ Startup
hGdip := DllCall("Kernel32.dll\LoadLibrary", "Str", "Gdiplus.dll") ; Load module
VarSetCapacity(GdiplusStartupInput, (A_PtrSize = 8 ? 24 : 16), 0) ; GdiplusStartupInput structure
NumPut(1, GdiplusStartupInput, 0, "UInt") ; GdiplusVersion
VarSetCapacity(pToken, 0)
DllCall("Gdiplus.dll\GdiplusStartup", "PtrP", pToken, "Ptr", &GdiplusStartupInput, "Ptr", 0) ; Initialize GDI+

BMPLogo := GdipCreateFromBase64(B64Logo, 2)
BMPLogoGoogle := GdipCreateFromBase64(B64LogoGoogle, 2)

; Free GDI+ module from memory
DllCall("Kernel32.dll\FreeLibrary", "Ptr", hGdip)

Gui, +LastFound -Resize
Gui, Margin, 0, 0
;Gui, Color, FF00FF
Gui, Add, Picture, x0 y0 w517 h78 +BackgroundTrans, % "HBITMAP:*" BMPLogo
Gui, Add, Picture, x20 y20 w272 h92 +BackgroundTrans, % "HBITMAP:*" BMPLogoGoogle

Gui, Show, AutoSize, Example
return

GdipCreateFromBase64(B64, RetType := 0) { ; 0=pBitmap, 1=HICON, 2=HBITMAP
	VarSetCapacity(B64Len, 0)
	DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", StrLen(B64), "UInt", 0x01, "Ptr", 0, "UIntP", B64Len, "Ptr", 0, "Ptr", 0)
	VarSetCapacity(B64Dec, B64Len, 0) ; pbBinary size
	DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", StrLen(B64), "UInt", 0x01, "Ptr", &B64Dec, "UIntP", B64Len, "Ptr", 0, "Ptr", 0)
	pStream := DllCall("Shlwapi.dll\SHCreateMemStream", "Ptr", &B64Dec, "UInt", B64Len, "UPtr")
	VarSetCapacity(pBitmap, 0)
	DllCall("Gdiplus.dll\GdipCreateBitmapFromStreamICM", "Ptr", pStream, "PtrP", pBitmap)

	If (RetType = 2) {
		VarSetCapacity(hBitmap, 0)
		DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "UInt", pBitmap, "UInt*", hBitmap, "Int", 0XFFFFFFFF)
	}

	If (RetType = 1) {
		DllCall("Gdiplus.dll\GdipCreateHICONFromBitmap", "Ptr", pBitmap, "PtrP", hIcon, "UInt", 0)
	}

	ObjRelease(pStream)

	return (RetType = 1 ? hIcon : RetType = 2 ? hBitmap : pBitmap)
}

Also, FYI -- https://www.autohotkey.com/boards/viewtopic.php?p=301384#p301384
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
guest3456
Posts: 3109
Joined: 09 Oct 2013, 10:31

Re: Image2Include - #include images in your scripts

15 Nov 2019, 10:21

dammtools wrote:
15 Nov 2019, 00:33
First of all, nice work so far.
Been trying to use your script, but I have no clue how to add more images in a GUI using this. Can you tell me how?
Um, just run the Image2Include.ahk script, pick an image, and the code will be generated.
Then just put the appropriate code in the Sample.ahk script

dammtools
Posts: 12
Joined: 11 Oct 2015, 18:02

Re: Image2Include - #include images in your scripts

16 Nov 2019, 18:56

Thanks guys. What an awesome work you guys are doing here. Keep it up!
User avatar
haichen
Posts: 461
Joined: 09 Feb 2014, 08:24

Re: Image2Include - #include images in your scripts

20 Nov 2019, 08:35

I tried to insert an image for a cursor. Unfortunately without success. Can you give me an example?

Code: Select all

;Example Code I used
x::SetSystemCursor(hwndBITMAP) 
x Up::RestoreCursors()
Return
SetSystemCursor(CursorHandle)
{
	IDC_SIZEALL := 32513
	;CursorHandle := DllCall( "LoadCursor", Uint,0, Int,IDC_SIZEALL )
	Cursors = 32512,32513,32514,32515,32516,32640,32641,32642,32643,32644,32645,32646,32648,32649,32650,32651
	Loop, Parse, Cursors, `,
	{
		DllCall( "SetSystemCursor", Uint,CursorHandle, Int,A_Loopfield )
	}
}

RestoreCursors() 
{
	SPI_SETCURSORS := 0x57
	DllCall( "SystemParametersInfo", UInt,SPI_SETCURSORS, UInt,0, UInt,0, UInt,0 )
}
nscience
Posts: 7
Joined: 07 Jun 2020, 18:29

Re: Image2Include - #include images in your scripts

07 Jun 2020, 18:48

Does it actually support Transparency?
From my testing with ImageSearch, it doesnt seem to be the case compared with the same search image as File.
Since i saw this: https://www.autohotkey.com/boards/viewtopic.php?t=63345 , im wondering if any of the used gdi+ functions may ignore Transparency and if, if it could be fixed?
iseahound
Posts: 552
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Image2Include - #include images in your scripts

08 Jun 2020, 04:21

I added Gdip_CreateARGBHBitmapfromBitmap and Gdip_CreateARGBBitmapfromHBitmap to the latest version of Gdip_All
robodesign
Posts: 652
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

Re: Image2Include - #include images in your scripts

08 Jun 2020, 08:37

Those functions are available in the extended compilation library edition as well. And, in addition, you can convert to/from base64 with this edition.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
nscience
Posts: 7
Joined: 07 Jun 2020, 18:29

Re: Image2Include - #include images in your scripts

08 Jun 2020, 18:38

Thank you for the answers guys! Now i just need to get used to the ahk gdip lib. Since im quite new to ahk, this is a steep step :)
So, as far as i understood, the available image2include.ahk script in its current form isnt updated yet to handle transparency, right?
nscience
Posts: 7
Joined: 07 Jun 2020, 18:29

Re: Image2Include - #include images in your scripts

20 Jun 2020, 19:25

@TheDewd or others:
when i run your script from above (https://www.autohotkey.com/boards/viewtopic.php?p=301385#p301385) it works fine when i run it uncompiled.
But if ran compiled, i get this instead:

https i.postimg.cc /L5xntwqH/image.png Broken Link for safety

any ideas whats wrong there?

solved: it used outdated/ansi.bin, needed the unicode one.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: comvox, rfmarves, robodesign and 155 guests