Friday, April 18, 2025

Embed image data directly in an autohotkey script

Have an AutoHotkey GUI that uses images and you want to imbed those images INTO your script code? (and not have to use a path to an image file?)

The script will convert your image files into autohotkey data that can exist in your AHK script.

1> Download this conversion tool

computoredge.com/AutoHotkey/Downloads/Image2Include.ahk

2> Run the tool

Pick the image file that you want to include into your script

(This example an image called "colors.png", which is a TV style color bar pattern, is used)

3> Click the CONVERT IMAGE button


            Script shows a "successfully created!" at the bottom

4> Click on "SHOW SCRIPT"

You'll see something like this.  Not the first portion "Create_colors_png".  That is the name that you use in your code for the image name.


5> COPY all of the code and PASTE it somewhere in your script.
It would be suggested to put it at the very bottom.

6> If you have some gui code already that is loading a picture, you just replace the dir/image name with the following code syntax

% "HBITMAP:*" . Create_colors_png()

(NOTE!  You need to have the double parathesis at the end!  don't forget those)

Here's a quick example GUI that will show the image, in my example, a color bar pattern

gui, add, Picture,  , % "HBITMAP:*" . Create_colors_png()
Gui, Show
msgbox press key to continue

; # This #Include file was generated by Image2Include.ahk, you must not change it!
; ############################################################
Create_colors_png(NewHandle := False) {
Static hBitmap := 0

...rest of code copy/pasted from the conversion script

And if you run it, will look like this:


If this tutorial has been of any help to you, I'd love to know! 
If you have suggestions of how to improve it, let me know in the comments!  Thanks!


No comments:

Post a Comment

Feel free to leave a comment! If you have any information that you think should be included, please do so here and I'll get it added in.