Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Get or Read Pixel from Memory UDF - PixelGetColor .au3


  • Please log in to reply
55 replies to this topic

#1 Manadar

Manadar

         

  • MVPs
  • 10,905 posts

Posted 31 January 2008 - 02:03 PM

Description:
This is an UDF to get a pixel from the memory. You first take a screenshot into memory, then use the pixel grabbing function as many times as you like, then call the destroy function. Please note that all of these functions are designed towards maximum performance. This means that nothing is actually released automatically so that the end-user can keep maximum control over what happens.


Author:
Original method: Greenseed
UDF: Manadar

Download:
Example:
AutoIt         
#include <_PixelGetColor.au3> #include <Misc.au3> $hDll = DllOpen("gdi32.dll") $vDC = _PixelGetColor_CreateDC($hDll) $vRegion = _PixelGetColor_CaptureRegion($vDC, 0,0,@DesktopWidth,@DesktopHeight,$hDll) ; click left mouse button to exit While Not _IsPressed(0x01)     $aPos = MouseGetPos()     $sColor = _PixelGetColor_GetPixel($vDC, $aPos[0],$aPos[1], $hDll)     ToolTip("The color under your mouse is: " & $sColor, $aPos[0]+3, $aPos[1]+3, "_PixelGetColor_GetPixel return",$hDll) WEnd _PixelGetColor_ReleaseRegion($vRegion) _PixelGetColor_ReleaseDC($vDC,$hDll) DllClose($hDll)




Benefits of using this method:
It's faster for capturing more pixels at once.
All the pixels can be captured at once, then read at your convenience anywhere in the script. You can capture multiple screens at once and compare them.
No problems with Vista (Aero) or Windows 7.

Drawbacks:
It's harder to implement.

Attached Files


Edited by Manadar, 16 April 2012 - 08:39 AM.

  • Xandy likes this







#2 NeoFoX

NeoFoX

    Adventurer

  • Active Members
  • PipPip
  • 141 posts

Posted 31 January 2008 - 04:17 PM

Nice script :D I'll definitly gonna use this one for my image-to-text prog.

But... you should alter your example script which is in your post between the codebox tags... because this one isn't working.
You haven't used any vars their on which screen to use the pixelgetcolor..


Neo

--- The Neo and Only --- --Projects---Image to Text converterText to ASCII converter


#3 Manadar

Manadar

         

  • MVPs
  • 10,905 posts

Posted 31 January 2008 - 09:28 PM

Nice script :P I'll definitly gonna use this one for my image-to-text prog.

But... you should alter your example script which is in your post between the codebox tags... because this one isn't working.
You haven't used any vars their on which screen to use the pixelgetcolor..


Neo

Thanks, I forgot to remove it. :D It was on of the older versions until I realized to not use any global variables in the include.

#4 marscom

marscom

    Seeker

  • Active Members
  • 27 posts

Posted 01 February 2008 - 08:03 PM

Amazing. Just amazing, I needed to do a PixelGetColour for about 190 (x,y) positions, was taking about 5-6 secs using the AutoIt function.

This is less than a second - brilliant.

One thing, I suggest creating some way of getting it to grab only a specific client window or window area, I fixed the problem by getting the window position from Au3Info and setting it up like this, with $win_title being your windows title.

    $windowinfo = WinGetPos ( $win_title)     $vRegion = _PixelGetColor_CaptureRegion($vDC, $windowinfo[0],$windowinfo[1],@DesktopWidth,@DesktopHeight)ƒo݊÷ Ù8b³¥–ÚÚrKa{§vŒ)¢È­Š‰ÚÚ'—(+i·ë¢kazÚ)•çí¡ûa{§vŒuا©è}û¶X¤zØb±«­¢+؀€€€˜ŒÀÌØíÙI•¥½¸€ô}A¥á•±•Ñ ½±½É} …ÁÑÕɕI•¥½¸ ˜ŒÀÌØíÙ °€˜ŒÀÌØíÝ¥¹‘½Ý¥¹™½lÁt¬Ì°˜ŒÀÌØíÝ¥¹‘½Ý¥¹™½lÅt¬È̱•Í­Ñ½Á]¥‘Ñ ±•Í­Ñ½Á!•¥¡Ð¤




With the offsets being - $windowinfo[0]+3,$windowinfo[1]+23

Will fix it to client pixel co-ord mode for vista, not sure what the offsets are for XP.

Regardless, brilliant work, my Script wouldnt be working without it biggrin.gif

Edited by marscom, 01 February 2008 - 08:06 PM.


#5 JRSmile

JRSmile

    MCSE 2012R2

  • Active Members
  • PipPipPipPipPipPip
  • 461 posts

Posted 01 February 2008 - 08:36 PM

pritty good work manadar *handclap*
but is it fast enough to capture for example a movie or a game?
i suppose that taking a screenshot takes some time and calculationg where the pixels are less time, so now the screenshot function is the bottleneck?
$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

#6 BillLuvsU

BillLuvsU

    Useless Member

  • Active Members
  • PipPipPipPipPipPip
  • 1,561 posts

Posted 01 February 2008 - 09:16 PM

Somebody needs to make a Guitar Hero bot with this. =]]] I could write it pretty easily but my computer can't run the game :) If somebody were to get me the pixel coords and hex colors of the note however, I could write the routines petty easily/quickly.

Edit: I would also need what keys to send to for the frets and strum, etc.

Edited by fear1313, 01 February 2008 - 09:18 PM.

Posted Image

Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

#7 Manadar

Manadar

         

  • MVPs
  • 10,905 posts

Posted 02 February 2008 - 02:12 AM

@JRSmile, I am not quite sure where the bottle neck is currently... It's probably at AutoIt's limitation to call these DLL's very fast since the other components are so fast.

Somebody needs to make a Guitar Hero bot with this. =]]] I could write it pretty easily but my computer can't run the game :) If somebody were to get me the pixel coords and hex colors of the note however, I could write the routines petty easily/quickly.

Edit: I would also need what keys to send to for the frets and strum, etc.


http://www.autoitscript.com/forum/index.php?showtopic=62681 :)

#8 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 02 February 2008 - 02:37 AM

@JRSmile, I am not quite sure where the bottle neck is currently... It's probably at AutoIt's limitation to call these DLL's very fast since the other components are so fast.



http://www.autoitscript.com/forum/index.php?showtopic=62681 :)


If your going to repeatedly call the dll, you might want to add a optional param of the dll, default to "dll.name" that way you can open with DllOpen and pass the handle in that should speed it up some.

SciTE for AutoItDirections for Submitting Standard UDFs

Don't argue with an idiot; people watching may not be able to tell the difference.


#9 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 05 February 2008 - 11:19 PM

@JRSmile, I am not quite sure where the bottle neck is currently... It's probably at AutoIt's limitation to call these DLL's very fast since the other components are so fast.



http://www.autoitscript.com/forum/index.php?showtopic=62681 :)



Still sick, but took a look at it, see what you think of the modifications: PixelGetColor.au3, modified example: _PixelGe...GetPixel.au3

Each header that has a Yes for Example is what would be expected to have examples for being all but 1 function was used in your example.

Edit: Removed Attachments

Edited by GaryFrost, 08 February 2008 - 02:53 AM.

SciTE for AutoItDirections for Submitting Standard UDFs

Don't argue with an idiot; people watching may not be able to tell the difference.


#10 Manadar

Manadar

         

  • MVPs
  • 10,905 posts

Posted 06 February 2008 - 11:41 AM

Still sick, but took a look at it, see what you think of the modifications: , modified example:

Each header that has a Yes for Example is what would be expected to have examples for being all but 1 function was used in your example.

Very good! I like what you did with all the _WinAPI functions, I had no idea. I noticed you didn't use $hDll in the _PixelGetColor_GetPixel function, but I see you meant to use it in the _PixelGetColor_GetPixelRaw function.

I have uploaded these files in the initial post. I still have to update the headers now and write an example for _PixelGetColor_GetPixelRaw.

Edited by Manadar, 06 February 2008 - 11:42 AM.


#11 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 06 February 2008 - 09:35 PM

Very good! I like what you did with all the _WinAPI functions, I had no idea. I noticed you didn't use $hDll in the _PixelGetColor_GetPixel function, but I see you meant to use it in the _PixelGetColor_GetPixelRaw function.

I have uploaded these files in the initial post. I still have to update the headers now and write an example for _PixelGetColor_GetPixelRaw.


I meant to pass it on in the Call to _PixelGetColor_GetPixelRaw from _PixelGetColor_GetPixel, missed adding that parameter in.

SciTE for AutoItDirections for Submitting Standard UDFs

Don't argue with an idiot; people watching may not be able to tell the difference.


#12 BillLuvsU

BillLuvsU

    Useless Member

  • Active Members
  • PipPipPipPipPipPip
  • 1,561 posts

Posted 07 February 2008 - 01:34 AM

http://www.autoitscript.com/forum/index.php?showtopic=62681 :)

wow... I evan posted in that topic... My brain is dieing more and more every day...

Posted Image

Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

#13 Delta01

Delta01

    Prodigy

  • Active Members
  • PipPipPip
  • 167 posts

Posted 27 February 2008 - 06:32 PM

Can it work on minimized windows?

#14 Manadar

Manadar

         

  • MVPs
  • 10,905 posts

Posted 05 March 2008 - 04:53 PM

Can it work on minimized windows?

Only if you screenshot the window first, and then minimize it. :)

#15 raquien

raquien

    Seeker

  • Active Members
  • 41 posts

Posted 09 May 2008 - 05:27 AM

hi manadar, would like to give this a try but i got '404' on the link.

#16 Uriziel01

Uriziel01

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 281 posts

Posted 09 May 2008 - 06:56 PM

I really need this function now, and I have no time to do it myself. Please upload it again Madanar :( Thx if you will do it !!
p.s-Oh! and also big THX for making all this stuff :)
Posted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted Image

#17 LiLShinta

LiLShinta

    Wayfarer

  • Active Members
  • Pip
  • 58 posts

Posted 11 May 2008 - 02:33 PM

yup kindly UL this UDF please.

#18 Manadar

Manadar

         

  • MVPs
  • 10,905 posts

Posted 11 May 2008 - 06:52 PM

I'm uploading this again once I have the files back. Currently lost them somewhere along the process of switching PCs.

#19 LiLShinta

LiLShinta

    Wayfarer

  • Active Members
  • Pip
  • 58 posts

Posted 12 May 2008 - 04:22 PM

cant wait. thanks.

#20 Manadar

Manadar

         

  • MVPs
  • 10,905 posts

Posted 13 May 2008 - 08:25 PM

I have it uploaded (Thanks to NeoFoX) but the example still is missing. I'm waiting for Gary to reply to this thread, see if he still has a version of the example.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users