AutoHotkey Community

It is currently May 27th, 2012, 1:57 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: January 27th, 2010, 9:45 pm 
Offline

Joined: January 7th, 2009, 7:03 pm
Posts: 43
I would like to distribute an AHK file without compiling, and without any other files to go along with it.

But my script uses image search, which requires a file.

Is there any way to, say, take the source (hex) of a gif / jpeg, put that into a variable, and use imagesearch on that variable?

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2010, 10:53 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
AFAIK, imagesearch doesn't support the ImageFile being in memory


http://www.autohotkey.com/forum/topic8682.html
this link I think is relevant because you can store an image as code in a file and retrieve it.

you could write the image to harddrive and then use it with imagesearch.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2010, 11:06 pm 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
If you have a standard repository (network or internet fileshare/website/pub FTP, anything), you could use IfExist and URLDownloadFile to make sure that your script always has the image files that it needs... i.e. downloaded by the client as necessary and not packaged in the file.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 29th, 2010, 8:43 pm 
Offline

Joined: January 7th, 2009, 7:03 pm
Posts: 43
Awesome, thanks for the replies.

Got it with the reply leef_me sent. I put the Hex into the ahk file, write to the windows users temp folder, read it, use it, then delete it. ( actually it wont delete, but ill figure that out later lol )

Simple as pie =D

In case anyone needs it.

It uses BinReadWrite.ahk

Code:
Image_TopNav_Separator =
( Join
 47 49 46 38 39 61 02 00 0B 00 A2 00 00 56 A0 D1 57 9F CF 55 A2 D6 07 62 97 0B 61 94 57 A1 D0 0A 61 97 00
 00 00 21 F9 04 00 00 00 00 00 2C 00 00 00 00 02 00 0B 00 00 03 09 48 30 42 61 05 CA 48 67 02 00 3B
)
StringReplace Image_TopNav_Separator, Image_TopNav_Separator, %A_Space%, , All

File := A_Temp . "\tmp.gif"
FileHandle := OpenFileForWrite(file)
Size := Hex2Bin(Data, Image_TopNav_Separator)
WriteInFile(FileHandle, Data, Size)
CloseFile(fh)

; Image searching goes here

; Delete it here, if we can figure it out... (  these dont work =(   )
; FileDelete, %A_Temp%\tmp.gif
; FileDelete, %File%
;


Here is the Hex2Bin function if you need it (i found it hard to find the right one)



Code:
/*
// Convert a string of hexa digit pairs to raw bytes stored in a variable.
// Convert either byteNb bytes or, if null, the whole content of the variable.
//
// Return the number of converted bytes, or -1 if error (memory allocation)
*/
Hex2Bin(ByRef @bin, _hex, _byteNb=0)
{
   local dataSize, granted, dataAddress, x

   ; Get size of data
   x := StrLen(_hex)
   dataSize := Ceil(x / 2)
   if (x = 0 or dataSize * 2 != x)
   {
      ; Invalid string, empty or odd number of digits
      ErrorLevel = Param
      Return -1
   }
   If (_byteNb < 1 or _byteNb > dataSize)
   {
      _byteNb := dataSize
   }
   ; Make enough room
   granted := VarSetCapacity(@bin, _byteNb, 0)
   if (granted < _byteNb)
   {
      ; Cannot allocate enough memory
      ErrorLevel = Mem=%granted%
      Return -1
   }
   dataAddress := &@bin

   Loop Parse, _hex
   {
      if (A_Index & 1)   ; Odd
      {
         x = %A_LoopField%   ; Odd digit
      }
      else
      {
         ; Concatenate previous x and even digit, converted to hex
         x := "0x" . x . A_LoopField
         ; Store integer in memory
         DllCall("RtlFillMemory", "UInt", dataAddress, "UInt", 1, "UChar", x)
         dataAddress++
      }
   }

   Return _byteNb
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot], engunneer, JSLover, rbrtryn, sjc1000, Yahoo [Bot] and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group