Sign in to follow this  
Followers 0

Get or Read Pixel from Memory UDF - PixelGetColor .au3

56 posts in this topic

Posted (edited)

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:

#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.

_PixelGetColor.au3

Example.au3

Edited by Manadar
Xandy likes this

Share this post


Link to post
Share on other sites



Posted

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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted (edited)

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{§vuا©è}û¶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

Share this post


Link to post
Share on other sites

Posted

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?

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

@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 :)

Share this post


Link to post
Share on other sites

Posted

@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.

Share this post


Link to post
Share on other sites

Posted (edited)

@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

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

Can it work on minimized windows?

Share this post


Link to post
Share on other sites

Posted

Can it work on minimized windows?

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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 :)

Share this post


Link to post
Share on other sites

Posted

yup kindly UL this UDF please.

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

cant wait. thanks.

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

thank you very much.!!

Share this post


Link to post
Share on other sites

Posted

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.

I believe it was:

#include <PixelGetColor.au3>
#include <Misc.au3>

$vDC = _PixelGetColor_CreateDC()

$vRegion = _PixelGetColor_CaptureRegion($vDC, 0,0,@DesktopWidth,@DesktopHeight)

$hDll = DllOpen("gdi32.dll")

; 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")
WEnd

DllClose($hDll)

_PixelGetColor_ReleaseRegion($vRegion)

_PixelGetColor_ReleaseDC($vDC)

Share this post


Link to post
Share on other sites

Posted

I believe it was:

#include <PixelGetColor.au3>
#include <Misc.au3>

$vDC = _PixelGetColor_CreateDC()

$vRegion = _PixelGetColor_CaptureRegion($vDC, 0,0,@DesktopWidth,@DesktopHeight)

$hDll = DllOpen("gdi32.dll")

; 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")
WEnd

DllClose($hDll)

_PixelGetColor_ReleaseRegion($vRegion)

_PixelGetColor_ReleaseDC($vDC)
This will not work because the function "_PixelGetColor_GetPixel" accepts two parameters not 4, and Autoit throws an error saying wrong number of parameters. Anyone have a working example, or know what to change?

Share this post


Link to post
Share on other sites

Posted (edited)

This one works for me, just had to remove the fourth parameter.

#include <PixelGetColor.au3>
#include <Misc.au3>

$vDC = _PixelGetColor_CreateDC()

$vRegion = _PixelGetColor_CaptureRegion($vDC, 0,0,@DesktopWidth,@DesktopHeight)

$hDll = DllOpen("gdi32.dll")

; click left mouse button to exit
While Not _IsPressed(0x01)
	$aPos = MouseGetPos()
	$sColor = _PixelGetColor_GetPixel($vDC, $aPos[0],$aPos[1])

	ToolTip("The color under your mouse is: " & $sColor, $aPos[0]+3, $aPos[1]+3, "_PixelGetColor_GetPixel return")
WEnd

DllClose($hDll)

_PixelGetColor_ReleaseRegion($vRegion)

_PixelGetColor_ReleaseDC($vDC)
Edited by xekon

Share this post


Link to post
Share on other sites

Posted

Sorry about that, Xekon. I had an old version up there.

Fixed in last update. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.