Sign in to follow this  
Followers 0
Rhyono

Screen capture mouse icon

4 posts in this topic

Using

#include <ScreenCapture.au3>
$MGP = MouseGetPos()
$hBitmap = _ScreenCapture_Capture("",$MGP[0]-3,$MGP[1],$MGP[0]+24,$MGP[1]+31,True)

I believe I'm properly getting an oversized, custom mouse cursor, but how would I then use PixelGetColor or another method to look at the pixels of that image? I do not want to save it.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Can you make some sense of this? I think this is the idea you are after.

$hscreen= _ScreenCapture_Capture("",$MGP[0]-3,$MGP[1],$MGP[0]+24,$MGP[1]+31,True)
$hbmpscreen= _GDIPlus_BitmapCreateFromHBITMAP($hscreen)
;free the handle
_WinAPI_DeleteObject($hscreen)
for $y= 0 to $h
 for $x= 0 to $w
  if _GDIPlus_BitmapGetPixel($hbmpscreen, $x, $y)= $pixelcolor then
   $pixelmatch+= 1
  endif
 next
next
_GDIPlus_BitmapDispose($hbmpscreen)

Get GDIP here (gdiPlus)

Edited by Xandy

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

When my code wasn't working right, I turned to the example of _GDIPlus_BitmapGetPixel, modified the code, and...

#include <GDIP.au3> 
#include <ScreenCapture.au3>
Opt("MustDeclareVars", 1)

_Example()

Func _Example()
Local $hBmp, $hBitmap, $iColor, $MGP

; Pause
Sleep(3000)

; Initialize GDI+
_GDIPlus_Startup()

$MGP = MouseGetPos()
$hBmp = _ScreenCapture_Capture("",$MGP[0]-3,$MGP[1],$MGP[0]+24,$MGP[1]+31,True)
; Create GDI+ Bitmap object from GDI Bitmap object
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
$iColor = _GDIPlus_BitmapGetPixel($hBitmap, 10, 14)

MsgBox(0x40, "Color", "Bitmap Pixel Color at [10, 14] is: 0x" & Hex($iColor,6))

; Clean up
_GDIPlus_ImageDispose($hBitmap)
_WinAPI_DeleteObject($hBmp)

; Uninitialize GDI+
_GDIPlus_Shutdown()
EndFunc

There we go.

Edited by Rhyono
1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#include <ScreenCapture.au3>
#include <GDIP.au3>
_gdiplus_startup()

Sleep(3000)
$MGP = MouseGetPos()
$hscreen= _ScreenCapture_Capture("",$MGP[0]-3,$MGP[1],$MGP[0]+24,$MGP[1]+31,True)
$hbmpscreen= _GDIPlus_BitmapCreateFromHBITMAP($hscreen)
;free the handle
_WinAPI_DeleteObject($hscreen)
$color = _GDIPlus_BitmapGetPixel($hbmpscreen, 10, 14);
MsgBox(0,"",Hex($color,6));
_GDIPlus_BitmapDispose($hbmpscreen)

_GDIPlus_ShutDown ()

returns msgbox F0F4F9 for me on XP 32bit

on vista and win_7 you may need to compile then tell the exe to run in compatibly mode for XP and disable the desktop composition in the comparability tab.

Those are things that I have done in the past for pixel detection.

Edited by Xandy

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