Sign in to follow this  
Followers 0
eEniquEe

How to get a Pixel Color in a bitmap captured by _ScreenCapture_Capture function?

5 posts in this topic

In the Help File, it says that:

_ScreenCapture_Capture:

If FileName is not blank this function will capture the screen and save it to file. If FileName is blank, this function will capture the screen and return a HBITMAP handle to the bitmap image. In this case, after you are finished with the bitmap you must call _WinAPI_DeleteObject to delete the bitmap handle.

So, what I understand is, if I don't specify any File Name, then the captured bitmap (captured from the screen) will be saved to the memory, isn't it?

The problem is, how can I extract a pixel out of this captured bitmap? And then read its color? Do I have to read the memory to do this? :-s If yes, can you guys give me a small lesson on how to do it, pls? I haven't met this kind of problem before, so I have absolutely no idea.. :D

Well, I can use the GetPixelColor to grab that pixel's color right from the screen, but it'll be amazingly slow if the number of pixels is large enough; and sometimes, not accurate at all, since all programmes running at that moment 'sync's themselves, so the pixel might get changed. So I think I should another way to get round this problem. :P

Thanks a lot in advance guys. :unsure:

Share this post


Link to post
Share on other sites



Try this:

#include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
HotKeySet("{ESC}","Quit")
_GDIPlus_Startup()
$hBitmap = _ScreenCapture_Capture("",0,0,@DesktopWidth,@DesktopHeight,False)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

While 1
    If _IsPressed('01') Then
        $POS = MouseGetPos()
        TrayTip("Pixel Color",_GDIPlus_BitmapGetPixel($hImage,$POS[0],$POS[1]),1)
    EndIf
    Sleep(20)
WEnd


Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
     Local $tArgb, $pArgb, $aRet
     $tArgb = DllStructCreate("dword Argb")
     $pArgb = DllStructGetPtr($tArgb)
     $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb)
     Return "0x" & Hex(DllStructGetData($tArgb, "Argb"))
 EndFunc ;==>_GDIPlus_BitmapGetPixel
 
 Func Quit()
     _GDIPlus_ImageDispose($hImage)
     _WinAPI_DeleteObject($hBitmap)
     _GDIPlus_Shutdown()
     Exit
 EndFunc

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks for giving me a big push, guys. :P

Now, it's like 5 time faster than scanning one pixel by one, using PixelGetColor function. :unsure: Many many thanks.. :D

Just out of curiousity, how do you "know" this DLL, and call it? I just wonder if you guys have any reference to some common DLLs, and its functions? Like this one:

$aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb)

Honestly, I recently realise that, without using dll's, and Users' Defined Functions, it's really hard, and sometimes, impossible to code in AutoIt; since its main functions are so few.. :( I know it'll be better if I start learning dll's, so can anyone recommend me some good sites that teach dll? Or, do you have any good .pdf, or book that you think should be a good start for me? :-?

Thanks once again. :D

Edited by eEniquEe

Share this post


Link to post
Share on other sites

Just out of curiousity, how do you "know" this DLL, and call it? I just wonder if you guys have any reference to some common DLLs, and its functions? Like this one:

$aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb)

Make from MSDN your friend.

http://msdn.microsoft.com/en-us/library/ms533971(VS.85).aspx


When the words fail... music speaks

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