AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is there a ImageSearch without a file?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
DevX



Joined: 07 Jan 2009
Posts: 43

PostPosted: Wed Jan 27, 2010 8:45 pm    Post subject: Is there a ImageSearch without a file? Reply with quote

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!
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Wed Jan 27, 2010 9:53 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Wed Jan 27, 2010 10:06 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
DevX



Joined: 07 Jan 2009
Posts: 43

PostPosted: Fri Jan 29, 2010 7:43 pm    Post subject: Reply with quote

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
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group