Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ADD AS 2ND COMMIT
- Use the Base64 String in AutoHotkey v2: In AutoHotkey v2, you can decode the base64 string and create an icon from it using the Windows API. Here’s an example script:
- base64_icon := "your_base64_string_here"
- ; Decode the base64 string
- decoded_icon := BufferAlloc(StrLen(base64_icon) * 3 // 4)
- DllCall("Crypt32.dll\CryptStringToBinaryA", "Str", base64_icon, "UInt", 0, "UInt", 1, "Ptr", decoded_icon.Ptr, "UIntP", decoded_icon.Size, "UInt", 0, "UInt", 0)
- ; Create an icon from the decoded data
- hIcon := DllCall("CreateIconFromResourceEx", "Ptr", decoded_icon.Ptr, "UInt", decoded_icon.Size, "Int", 1, "UInt", 0x00030000, "Int", 0, "Int", 0, "UInt", 0)
- ; Use the icon (e.g., set it as the tray icon)
- Menu("Tray").SetIcon(hIcon)
- The expression * 3 // 4 is used to calculate the size of the buffer needed to store the decoded base64 data. Here’s a breakdown:
- Base64 Encoding: Base64 encoding converts binary data into a text string using 64 different ASCII characters. Every 3 bytes of binary data are encoded into 4 characters of base64 text.
- Decoding: When decoding, you need to reverse this process. For every 4 characters of base64 text, you get back 3 bytes of binary data.
- So, if you have a base64 string of length n, the size of the decoded binary data will be approximately n * 3 / 4. In the script, this is written as StrLen(base64_icon) * 3 // 4, where
- StrLen(base64_icon) gives the length of the base64 string, and * 3 // 4 calculates the size of the buffer needed to store the decoded data.
Add Comment
Please, Sign In to add comment