[Gdip] Use Base64 PNG data with Gdip? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: [Gdip] Use Base64 PNG data with Gdip?

30 Nov 2018, 07:32

guest3456 wrote:
29 Nov 2018, 23:30
i'll happily accept a pull request. i think we need some documentation within the func on how to create the base64 string to begin with (i saw a SKAN link earlier up in this thread?). or could even add a new Example file too to the lib

and i'm not sure if just a boolean param at the end is sufficient for return type. seems like TheDewd now has ways to return either HICON, hBitmap, or pBitmap. do we want all those options? i argue no. i think it should just return the pBitmap and be named "Gdip_CreatBitmapFromBase64()" for consistency. because, the lib already has the wrapper funcs to convert a pBitmap into an hBitmap or hIcon that the user can simply nest the funcs on top of each other if they need those other formats. most of the lib works with simply pBitmaps

I agree that returning only pBitmap should be sufficient, and then have separate functions to return either HICON or HBITMAP instead of having it as an all-in-one function.

I created the function to be unique to the project I was working on at the time. It makes perfect sense to keep the functions separate if the intent is to add them to the GDI+ library.

Yes, it seems that SKAN does have an example of converting images to a Base64 string. See https://autohotkey.com/boards/viewtopic ... 07#p165507

To compress images for my personal projects, I've been using Compress-Or-Die. They have an option for "extreme" compression that shortens the Base64 string even further than some of the other websites I've used in the past. I'm not suggesting to use a website in the documentation for converting an image to Base64 -- I just wanted to share the website in case anyone else might find the "extreme" compression option useful.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
dammtools
Posts: 12
Joined: 11 Oct 2015, 18:02

Re: [Gdip] Use Base64 PNG data with Gdip?

15 Nov 2019, 00:39

TheDewd wrote:
29 Nov 2018, 15:47
I modified the function for a new project so that I can assign the images to a Picture control.

The previous function will return the pBitmap pointer, but I added an extra DllCall to convert pBitmap to hBitmap.

See example below:

Code: Select all

#SingleInstance, Force

B64Logo := "iVBORw0KGgoAAAANSUhEUgAAAgUAAABOCAMAAACHQpW5AAACxFBMVEVHcEwADhwAGTMACBE/V24AAAA/V24AKlVra2sAAAAAAABra2s/V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TBF3UvWiBoijnNVeYzlermZldt8pEkaF7kqALiHP+kefnCh6We5l3TqMouGMV9EB1rhxOHz6wvtEFCHv79huv9/mY2pMEfe2T/sVL1rx7d1N1h+Wm6gO6qefLzR0bd43L7YbvMQgA7t7Y7q0bMpHI5mHN3B80nBfJbNu5KT5uqgPD91gESkyBXvOW7aGQw+GY9ZMcKLQsFm4KyDIABz0GgVKf2+0cR17vzJ/X29vbGI3K7e3tHPSYBABCJlF0xq8xmQjBncxFj02gtK6OECL/AqLCfcxLj00AFf0lgDjoMQlfAb70ei22uKsoAAAAAElFTkSuQmCC"

; 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)

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

Gui, +LastFound -Resize
Gui, Margin, 0, 0
Gui, Add, Picture, x0 y0 w517 h78, % "HBITMAP:*" BMPLogo
Gui, Show, AutoSize, Example
return

GdipCreateFromBase64(B64, IsIcon := 0) {
	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)
	VarSetCapacity(hBitmap, 0)
	DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "UInt", pBitmap, "UInt*", hBitmap, "Int", 0XFFFFFFFF)

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

	ObjRelease(pStream)
	return (IsIcon ? hIcon : hBitmap)
}
This is awesome. Tried if I could use more images in a GUI with this and worked like a charm.
Just one question: does this removes transparency from PNG images? In my tests I overlapped two images to test it and it seems transparency is gone. Can you confirm this, please?
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: [Gdip] Use Base64 PNG data with Gdip?

15 Nov 2019, 08:35

dammtools wrote:...does this removes transparency from PNG images? In my tests I overlapped two images to test it and it seems transparency is gone. Can you confirm this, please?
You will need to use +BackgroundTrans on the image to make it transparent when you do the overlapping.

Code: Select all

#SingleInstance, Force

B64Logo := "iVBORw0KGgoAAAANSUhEUgAAAgUAAABOCAMAAACHQpW5AAACxFBMVEVHcEwADhwAGTMACBE/V24AAAA/V24AKlVra2sAAAAAAABra2s/V3IAAAAAAABra2tra2sAAAAAChQ/VHM/P3k/V3Nr//8AAAA/X24/V24/V25r//9ra2sAAAA/VHA/V3Bra2s/VHI/XG4AAAI/WnNra2s/VG4AAABra2sAAABra2tra2sAEiQAAABra2tra2tra2tra2sAAAAADBcAIEAAAAAAAAAAAAAAFSoAAAkADRkABw8AAAAAAAAAAAAAAAAAAAAABgYAAAAAAAAAAAAAAAAAAAAAECDX2NmwsLHQ0NDAxcqys7PZ2dlaWlulpaXi4uJJSUo5OTlHR0fe398ABQu6urvi4+RcXF1MTU2qqqqPj5DX2NimpqZgYGAAAABFRUUAAAAAAAAAAAAAAAAAAAAAAACNj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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)

; 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 w517 h78 +BackgroundTrans, % "HBITMAP:*" BMPLogo

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)
}
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
dammtools
Posts: 12
Joined: 11 Oct 2015, 18:02

Re: [Gdip] Use Base64 PNG data with Gdip?

16 Nov 2019, 18:53

TheDewd wrote:
15 Nov 2019, 08:35
You will need to use +BackgroundTrans on the image to make it transparent when you do the overlapping.
Thank you Sir.!!!
dammtools
Posts: 12
Joined: 11 Oct 2015, 18:02

Re: [Gdip] Use Base64 PNG data with Gdip?

20 Nov 2019, 06:31

One last question: does this have retro compatibility with Windows XP?

Return to “Ask For Help”

Who is online

Users browsing this forum: boiler, burque505, Forgetabyteit, vsub, WeThotUWasAToad, yuyu and 142 guests