Jump to content

Get Pixel Problem


Recommended Posts

I made this script to get a pixel color when you click.

Opt("PixelCoordMode",2)
Opt("MouseCoordMode",2)
Opt("ColorMode", 0)
#Include <Misc.au3>
$v_dll = 'user32.dll'
$mschk = MouseGetPos()
while 1
 
if _IsPressed(01,$v_dll) then 
$mschk = MouseGetPos()
$colorwin = PixelGetColor($mschk[0], $mschk[1])
$ms = MsgBox(1,"",$colorwin & @CRLF & "X =" & $mschk[0] & "  Y = " & $mschk[1])
 if $ms = 2 then 
  exit
 endif 
endif
sleep(20)
WEnd

I expect the format on the return to be in the format 0xRRGGBB, What I get is this: 16777215

According to the help file, I can set the colormode to RGB by setting it to "0", but this makes no difference.

:)

Link to comment
Share on other sites

  • Moderators

in further reading of the helpfile, I find the sentence where it says "Returns decimal value of pixel's color." Now I get it, but how do I get it to return the RGB value?

Hmmm, It returns RGB automatically (You'd have to do something entirely different to get BGR), it returns it in decimal, if you want the "Hex" value, simply do:
$var = '0x' & Hex(PixelGetColor(x, y), 6)

Edit:

This is assuming as long as you've been using AutoIt that your using the latest beta of course :)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Ah, I put in the code, and it works nicely. I coded it so it will return both ways.

Opt("PixelCoordMode",2)
Opt("MouseCoordMode",2)
Opt("ColorMode", 0)
#Include <Misc.au3>
$v_dll = 'user32.dll'
$mschk = MouseGetPos()
while 1
 
if _IsPressed(01,$v_dll) then 
$mschk = MouseGetPos()
$colorwin = PixelGetColor($mschk[0], $mschk[1])
$colorwin1 = '0x' & Hex(PixelGetColor($mschk[0], $mschk[1]), 6)
$ms = MsgBox(1,"",$colorwin & "  = Decimal value" & @CRLF & $colorwin1 & "  = Hex value"& @CRLF & "X =" & $mschk[0] & "  Y = " & $mschk[1])
 if $ms = 2 then 
  exit
 endif 
endif
sleep(20)
WEnd

I'm thinking of adding this to the SciTE toolbar. Thoughts?

Edited by vollyman
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...