Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)
Re: Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)
Should be also possible with ComObjCreate("Msxml2.DOMDocument"), createElement("base64") and dataType := "bin.base64"
Re: Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)
Code: Select all
hICON := b64Decode(PNG10x10, 48, 48)
b64Decode(b64, w := 16, h := 16) ; borrowed from uberi
{
static CharSet := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
VarSetCapacity(bin, Ceil(((len := StrLen(b64)) / 4) * 3), 0), i := 1, p := 0
loop % len // 4 {
b := ((InStr(CharSet, SubStr(b64, i, 1), true) - 1) << 0x12)
| ((InStr(CharSet, SubStr(b64, i + 1, 1), true) - 1) << 0x0c)
| ((InStr(CharSet, SubStr(b64, i + 2, 1), true) - 1) << 0x06)
| ((InStr(CharSet, SubStr(b64, i + 3, 1), true) - 1) )
NumPut((b >> 0x10) | (((b >> 0x08) & 0xff) << 0x08) | ((b & 0xff) << 0x10), bin, p, "uint")
i += 4, p += 3
}
if (len & 3) {
b := ((InStr(CharSet, SubStr(b64, i, 1), true) - 1) << 0x12) | ((InStr(CharSet, SubStr(b64, i + 1, 1), true) - 1) << 0x0c)
NumPut(b >> 0x10, bin, p, "uchar")
if (len & 1) {
b |= ((InStr(CharSet, SubStr(b64, i + 2, 1), true) - 1) << 0x06)
NumPut((b >> 0x08) & 0xff, bin, p + 1, "uchar")
}
}
return DllCall("CreateIconFromResourceEx", "ptr", &bin, "uint", len, "int", true, "uint", 0x30000, "int", W, "int", H, "uint", 0, "uptr")
}
Re: Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)
SKAN wrote: Its my policy. I will specifically mention, if my function is not meant for XP.

round(strlen(B64)/4*3) or round(strlen(strReplace( B64,"=","=",e))/4*3-e), either will work, I prefer the first. I wouldn't do the floor, I'd worry about potentally rounding down exactSize-0.0000000000x to exactSize-1 when there is no padding.SKAN wrote:A perfect one-liner to avoid the additional DllCall() would be a good improvement for that function.
I guess you eliminate the size calculation dllcall for the Base64Enc function too, nChars:=ceil(nBytes/4*3)+linebreaks+spaces.

@ jNizM, hi and interesting code


Cheers.
Re: Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)
@ jNizM
Thanks for sharing
PS: I miss uberi.

Thanks for sharing

PS: I miss uberi.
Thank you. I will test it and reply.Helgef wrote:round(strlen(B64)/4*3) or round(strlen(strReplace( B64,"=","=",e))/4*3-e), either will work, I prefer the first.

Base64PNG_to_HICON() - Updated
I tested well. round(strlen(strReplace( B64,"=","=",e))/4*3-e) works wellI wrote:Thank you. I will test it and reply.Helgef wrote:round(strlen(B64)/4*3) or round(strlen(strReplace( B64,"=","=",e))/4*3-e), either will work, I prefer the first.![]()

I've updated the code with this slightly modified floor version from @jeeswg : bytes := floor(strlen(RTrim( B64,"="))*3/4)
PNG_to_HICON()
I was searching for something else and landed on this ask-for-help topic
LoadPicture to use it as icon by @john_c
So, here is the modified version of Base64PNG_to_HICON() which
loads ICON from a PNG file.
LoadPicture to use it as icon by @john_c
So, here is the modified version of Base64PNG_to_HICON() which
loads ICON from a PNG file.
Code: Select all
PNG_to_HICON(File, W:=0, H:=0) { ; By SKAN
FileRead, Bin ,*c %File%
Return DllCall("CreateIconFromResourceEx", "Ptr",&Bin, "UInt",VarSetCapacity(Bin)
, "Int",True, "UInt",0x30000, "Int",W, "Int",H, "UInt",0, "UPtr")
}
; DEMO
#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir %A_ScriptDir%
UrlDownloadToFile, https://www.autohotkey.com/assets/images/ahk-logo-no-text241x78-180.png, ahk.png
Gui, Add, Picture,, % "HICON:" PNG_to_HICON("ahk.png")
Gui, Show
Return
Re: Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)
Very useful! Thank you!
Return to “Scripts and Functions”
Who is online
Users browsing this forum: jly, robodesign and 16 guests