Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Include a bitmap in your uncompiled script!!!

  • Please log in to reply
84 replies to this topic
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Yes, exaclty what GIF makesr do when you optimise the GIF.
Posted Image

  • Guests
  • Last active:
  • Joined: --

i think this si exactly what iam looking for.

is here something new? plz tell me how i can use a hex code for show pics in the script?

what funktion i need? Or ist there a GUI out for this?


  • Guests
  • Last active:
  • Joined: --
sry for DP, its me again!

i love the code you post of the first page.

Plt can you say how i can do the same but with ico formats?

cause when i use bmp i have no transparency!

  • Members
  • 252 posts
  • Last active: Jul 20 2015 03:25 AM
  • Joined: 21 Nov 2006
I have a bitmap file (46.9k big)

When using this script, I get an error stating that the line is too long. Is there anyway to fix this?

I've already tried :

data =
( join

data = %data%`n

Each section contained no more than 14,000 characters and it still errors out on me.

Please help!

  • Guests
  • Last active:
  • Joined: --

Each section contained no more than 14,000 characters and it still errors out on me.

declare into a variable without section.

in other words: a single line.

  • Guests
  • Last active:
  • Joined: --
Hi, I am very worried with this routine below. I have been working on it for many nights, trying to figure out why it runs out of memory.

I think I am doing everything correctly... but cannot say for sure. I have looked at many examples in this thread, and other places... but nothing seems to jump out at me at what I might be missing.

I don't know if there are additional things I need to 'reset' or clear out before the loop restarts...., that might be causing the problem of the script eventually crashing.

Thank you for anyone who can figure this out! This has me really stumped. I am disposing the bitmap, ... however, you'll notice %COUNT_SUM_PDATA% grows over time until the script crashes. I had about 50 decent sized PNG images in the folder, and a crash eventually happens!

You need to run this script, with a_directory_with_some_pngfiles folder in the script directory. I threw about 3 dozen PNG image files that were between 250K-300K in size. The code loop below demonstrates processing of each image, from a file to a bitmap. Extra code comments are below.

; press a to test loop






; ---------------------------------------------
; ---------------------------------------------


; ----- setup test variables



; ---------------------------------------------

Loop, a_directory_with_some_pngfiles\*.*

FileGetSize, dataSz , a_directory_with_some_pngfiles\%A_LoopFileName%
FileRead, BinData , a_directory_with_some_pngfiles\%A_LoopFileName%

hexData := Bin2Hex( &BinData, dataSz )

; ^ Convert Image To Hex Data

nSize := StrLen(hexData)//2

hData := DllCall("GlobalAlloc", UInt,2, UInt, nSize)
pData := DllCall("GlobalLock",  UInt,hData)
DllCall( "RtlMoveMemory", UInt,pData, UInt,&Buffer, UInt,nSize)
DllCall( "GlobalUnlock", UInt,hData)
DllCall( "ole32\CreateStreamOnHGlobal", UInt,hData, Int,True, UIntP,pStream)

DllCall( "LoadLibrary", Str,"gdiplus" )
VarSetCapacity(si, 16, 0), si := Chr(1)

DllCall( "gdiplus\GdiplusStartup", UIntP,pToken, UInt,&si, UInt,0 )
DllCall( "gdiplus\GdipCreateBitmapFromStream", UInt,pStream, UIntP,bitmap)


GDIplus_GetImageDimension(bitmap, WIDTH_OF_IMAGE, HEIGHT_OF_IMAGE)

DllCall( "gdiplus\GdipDisposeImage", UInt,bitmap)


; ^ Uncomment To See Each File Processed - If processing correctly we should see a %WIDTH_OF_IMAGE% x %HEIGHT_OF_IMAGE%

; - end of loop




[color=red]FileAppend, %COUNT_SUM_HDATA% | > why does this var grow over time, until script crashes? ---> %COUNT_SUM_PDATA% <--- | %COUNT_SUM_NSIZE%`n,TESTING_OUTPUT.TXT[/color]

; ^ test output data


Here are the extra stock functions which make it all work :)

GDIplus_GetImageDimension(_image, ByRef @imageWidth, ByRef @imageHeight)
	local r

   #GDIplus_lastError =
	r := DllCall("GDIplus.dll\GdipGetImageDimension"
			, "UInt", _image
			, "Float *", @imageWidth
			, "Float *", @imageHeight)
	If (r != #GDIplusOK)
		#GDIplus_lastError := "GdipGetImageDimension (" . r . ": " . #[email protected]%r% . ") " . ErrorLevel
	@imageWidth := Floor(@imageWidth)
	@imageHeight := Floor(@imageHeight)
	Return r


  Bin2Hex() and Hex2Bin()

  Machine code functions: Bit Wizardry [ By Laszlo Hars ]

  Topic : http://www.autohotkey.com/forum/viewtopic.php?t=21172
  Post  : http://www.autohotkey.com/forum/viewtopic.php?p=180469#180469


Bin2Hex(addr,len) { ; Bin2HexGOLD(&x,4)

   Static fun
   If (fun = "")
      . "2AC2044188018A06240F2C0A8AD0C0EA052AC2410441468801414F75D75EC601005FC3")
   dllcall(&fun, "uint",&hex, "uint",addr, "uint",len, "cdecl")
   VarSetCapacity(hex,-1) ; update StrLen
   Return hex

Hex2Bin(ByRef bin, hex) { ; Hex2Bin(fun,"8B4C24") = MCode(fun,"8B4C24")
   Static fun
   If (fun = "") {
       . "a164684d2741a8ac2c0e806b309f6eb80e20f02c20ac188078a16474684d275cd5b5f5ec3"
      Loop % StrLen(h)//2
         NumPut("0x" . SubStr(h,2*A_Index-1,2), fun, A_Index-1, "Char")
   dllcall(&fun, "uint",&bin, "Str",hex, "cdecl")

  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006

...declare into a variable without section.

in other words: a single line.

Had to bump this one.

I too am getting an error message that the line is too long on a single line binary string. It was generated from the converter on the 1st page.

I'm wondering, what is the exact max characters allowed??

Anyone know?

Thanks guys for this amazing (albeit old) work.

Posted Image

don't duplicate, iterate!

  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Ok I had a chance to put together a continuation section concatenater that works around the binary character limitation.
1st off I found out that each continuation section can contain 16371 characters max not 16383 as stated in the manual :roll: (not sure if this is a bug, something to do with a join continuation or the number needs to be changed in the manual).

This section of code creates the template script "NewBinaryFile.ahk" in its working directory. This is just a proof of concept version. Once I confirm everything is working I will add this to an updated version of BMP to Binary.
fileExt = jpg
fileName = Test
outputFile = %A_WorkingDir%\NewBinaryFile.ahk
mxLen := 16371
FileDelete, %outputFile%

    FileRead, bindat, %A_WorkingDir%\bindat.txt
    StringLen, bindatLen, bindat
    brkCount := Round(bindatLen /= mxLen)
        if brkCount = 0
	brkCount = 1

    Loop, %brkCount%
	StringLeft, curBin, bindat, %mxLen%
	newBinBrk := "binaryData" A_index " =`n( join`n" curBin "`n)`n`n"
	    FileAppend, %newBinBrk%, %outputFile%
	    StringReplace, bindat, bindat, %curBin%,,
	        contSects .= "binaryData" A_index " . "
    StringTrimRight, contSects, contSects, 3
    contSects := "binData .= " contSects "`n`nReturn`n`ncloseOut:`nMsgbox, Conversion Complete!`nExitApp"
    FileAppend, %contSects%, %outputFile%

FileRead, newBinDat, %outputFile%
FileDelete, %outputFile%
    writeSect .= "fileLoc = " "%A_WorkingDir%\" fileName "." fileExt "`ngosub, defineFile`nWriteFile(fileLoc,binData)"

prependDat =
#SingleInstance Force
OnExit, closeOut




; Binary file conversion thanks to Veovis, Laszlo, PhiLho and I'm sure SKAN had something to do with it ;).
; Found here: http://www.autohotkey.com/forum/viewtopic.php?t=10957

   Handle :=  DllCall("CreateFile","str",file,"Uint",0x40000000
     if strlen(data) = 0
     StringLeft, Hex, data, 2         
     StringTrimLeft, data, data, 2 
     Hex = 0x`%Hex`%
     DllCall("WriteFile","UInt", Handle,"UChar *", Hex
     ,"UInt",1,"UInt *",UnusedVariable,"UInt",0)
   DllCall("CloseHandle", "Uint", Handle)

    FileAppend ,%prependDat%`n%newBinDat%, %outputFile%


NewBinaryFile.ahk then reads the bindat.txt created from a mod'd version of BMP to Binary found on the 1st page of this thread). It can then be used as a template script that converts the binary to images and joins sections over the max char limt that can be used in a script. Simply edit NewBinaryFile.ahk to see how many sections are created and add your code to this section:



For this example save bindat.txt to the same directory as NewBinaryFile.ahk




When there are many continuation sections the conversion process is quite slow but it does work!

I'm going to integrate this into a mod'd version of BMP to Binary converter that will automatically create the script template. That way there will be no need for the external bindat.txt file.

Soon to come...

BTW just noticed that long binary sections actually break the forum (turns a post into blank). So the next question is what the max line length in a single post admins ? :lol:

Posted Image

don't duplicate, iterate!

  • Members
  • 45 posts
  • Last active: Feb 13 2014 04:49 AM
  • Joined: 01 Mar 2010
I want to use Veovis's GUI from page 1 of this topic to have my .png files included in the compiled scripts, so I will have a single .exe.
But I want to use ImageSearch inside the script also. It works as long as I use the WriteFile function to read the image from disk, but it does not work for me if I call the %picture%
picture = (join...)

I searched deeper in the forum and I found this:

"is there a way to embedded image with imagesearch and compiled version as well ?"

SKAN Posted: Tue Aug 04, 2009 4:42 pm

Also I found a topic where someone suggested to write the images in a %TEMP% and delete them afterwards.

So if I am understanding right, we cannot use the ImageSearch function unless we WriteFile somewhere? Not following why since the image is in the memory already. Theres smth wrong in my code (hopefully) or it is not possible yet? Thanks.