Encoding Binary data to a string

Helpful script writing tricks and HowTo's
User avatar
Joe Glines
Posts: 646
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Encoding Binary data to a string

23 Sep 2019, 07:56

In the second half of our webinar on Finding and Clicking Text / Pixels / Images someone asked about encoding a binary image to Base64, then being able to decode it back for usage (this will allow them not to have to share the actual image files.)

I've never done any of this so I was lost but thankfully Jackie and Maestrith had experience in it.   The other night I mentioned it to Maestrith and he generously offered to work through a couple of examples and explain the process to me.

Please keep in mind, this wasn't a planned tutorial.  He did it on the fly and we just worked through things.  For me it was very illuminating!

Encoding binary data to a string Tutorial

Code: Select all

Bits:="100011010010010101011001010"
Bits:="Hq"

/*
	0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
	
	0=0
	1=1
	2=10
	3=11
	4=100
	5=101
	6=110
	7=111
*/

Gui,Add,Edit,gGo w500 Number
Gui,Add,UpDown,Range1-5000 +0x80,1
Gui,Add,Text,w500
Gui,Show
return
GuiEscape:
ExitApp
return
Go(){
	ControlGetText,i,Edit1,A
	ControlSetText,Static1,% ((i>>8&1)(i>>7&1)(i>>6&1)(i>>5&1)(i>>4&1)(i>>3&1)(i>>2&1)(i>>1&1)(i&1)),A
}
User avatar
TheDewd
Posts: 1352
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Encoding Binary data to a string

26 Sep 2019, 14:12

Joe Glines wrote:
23 Sep 2019, 07:56
...encoding a binary image to Base64, then being able to decode it back for usage (this will allow them not to have to share the actual image files.)

Joe,

My game "Bulldozer" makes use of encoding PNG images to Base64 to prevent having to include external images when sharing the script file.

The PNG image files are never written to disk -- they are always read from memory.

I thought it might be relevant to what you had mentioned regarding Base64 and images.

AutoHotkey: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=50139
GitHub: https://github.com/westoncampbell/BulldozerAHK

Script: https://raw.githubusercontent.com/westoncampbell/BulldozerAHK/master/Releases/Bulldozer%20-%20Revision%2018%20(2019-05-09).ahk
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
Joe Glines
Posts: 646
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Encoding Binary data to a string

26 Sep 2019, 14:42

TheDewd wrote:
26 Sep 2019, 14:12
My game "Bulldozer" makes use of encoding PNG images to Base64 to prevent having to include external images when sharing the script file.
Thanks! We actually came out with a working solution during the webinar but always great to have more examples!

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 31 guests