Jump to content

Problem with _ColorGetRed


Recommended Posts

I have this code and a problem with _ColorGetRed and the others.

It doesn't turn anything but 0's.

$decColor = PixelGetColor ($getPixelColorX, $getPixelColorY)
    $hexColor = Hex($decColor)
    $redColor = _ColorGetRed($hexColor)
    $greenColor = _ColorGetGreen($hexColor)
    $blueColor = _ColorGetBlue($hexColor)

In the rest of the code I don't use that functions.

What I am doing wrong?

Thx in advance for the help!

Sry for my english.

Edited by Soulstriker
Link to comment
Share on other sites

Here are three ways of getting the colour channel value.

_ColorGetRed() from Color.au3 include file.

I believe your mistake was not having the "0x" prefix in the RGB color parameter.

String manipulation.

The use of any string function to get "RR", or "GG", or "BB" colour channel values from a rgb colour in a hex colour format of "0xRRGGBB".

Bit-wise operations.

Using bit operations on a 24 bit or 32 bit colour in the hex format of 0xRRGGBB or 0xAARRGGBB, respectively.

#include <Color.au3>

Local $getPixelColorX = 10, $getPixelColorY = 100

$decColor = PixelGetColor($getPixelColorX, $getPixelColorY)
ConsoleWrite($decColor & @CRLF)
$hexColor = "0x" & Hex($decColor)
ConsoleWrite($hexColor & @CRLF)
$redColor = Hex(_ColorGetRed($hexColor), 2)
ConsoleWrite("ColorGet Red = " & $redColor)
$greenColor = Hex(_ColorGetGreen($hexColor), 2)
ConsoleWrite("; Green = " & $greenColor)
$blueColor = Hex(_ColorGetBlue($hexColor), 2)
ConsoleWrite("; Blue = " & $blueColor & @CRLF)

ConsoleWrite("Strings " & StringRegExpReplace(Hex($decColor, 6), "(.{2})(.{2})(.{2})", "Red = \1; Green = \2; Blue = \3") & @CRLF)


ConsoleWrite("Bit Ops Red = " & Hex(BitShift(BitAND($hexColor, 0xFF0000), 16), 2) & _
        "; Green = " & Hex(BitShift(BitAND($hexColor, 0x00FF00), 8), 2) & _
        "; Blue = " & Hex(BitAND($hexColor, 0x0000FF), 2) & @CRLF)
Link to comment
Share on other sites

  • Moderators

Soulstriker,

A good tip: when you do not get what you are expecting out of series of commands like this, add some ConsoleWrite lines to your script and see what you are getting at each stage. ;)

In this particular case Hex will, unless you specify otherwise, return a basic 8-character hex string - from the Help file:

"Success: Returns a string of length characters, zero-padded if necessary for integer."

So you are getting the string "00######" returned from Hex. However, if you look at the Help file for the _ColorGet* functions, you see that they require the the hex to be in 6-character number form, i.e. preceded by "0x". So it is hardly surprising that you are not getting the correct output. :evil:

Look at this:

#include <Color.au3>

$decColor = PixelGetColor(100, 100)
ConsoleWrite($decColor & @CRLF)

$hexColor = Hex($decColor)
ConsoleWrite($hexColor & @CRLF) ; Your original line - note 8 hex char string

$hexColor = "0x" & Hex($decColor, 6)
ConsoleWrite($hexColor & @CRLF) ; My new line - note 6 char hex number format beginning with 0x

$redColor = _ColorGetRed($hexColor)
ConsoleWrite(Hex($redColor, 2) & @CRLF) ; Just to reinforce the Hex point - a 2 hex char string

$greenColor = _ColorGetGreen($hexColor)
ConsoleWrite($greenColor & @CRLF)

$blueColor = _ColorGetBlue($hexColor)
ConsoleWrite($blueColor & @CRLF)

Because AutoIt uses untyped variables (which in the opinion of most is one of its strengths :evil: ) it is up to you to make sure that you are using the correct type or format for the variables you use with the different functions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thank you very much both for the tips! I've read something about the opt TrayIconDebug but I can't get it to work. ;)

On the other hand I still need some help with another issue.

Im trying to use this program and I need to get some information of it.

Specifically, the information displayed in the status bar at the bottom and the "xxx" colors, below the update button.

I tried reading it with the autoit window info, without succes.

Any help?

Thx!!

Soul.-

Edited by Soulstriker
Link to comment
Share on other sites

I have this code and a problem with _ColorGetRed and the others.

It doesn't turn anything but 0's.

$decColor = PixelGetColor ($getPixelColorX, $getPixelColorY)
    $hexColor = Hex($decColor)
    $redColor = _ColorGetRed($hexColor)
    $greenColor = _ColorGetGreen($hexColor)
    $blueColor = _ColorGetBlue($hexColor)

In the rest of the code I don't use that functions.

What I am doing wrong?

Thx in advance for the help!

Sry for my english.

I know you have gone away from the original post but I want to comment on the misunderstanding/ misinformation in the above posts and which is not uncommon in these forums.

The problem with your code was simply that you didn't use the returned value from PixelGetColor as the parameter for _ColorGet***. The suggestion that this parameter has to be written in hexidecimal format is wrong. A number is the same value whatever format is used, so the following code would be quite ok.

$decColor = PixelGetColor($getPixelColorX, $getPixelColorY)
$redColor = _ColorGetRed($decColor)
$greenColor = _ColorGetGreen($decColor)
$blueColor = _ColorGetBlue($decColor)

I think the confusion arrises because of a comment in the help that the parameter must be a RGB value (hexidecimal code). This only means that the red green and blue components are neatly split into that sequence when shown as a hexidecimal value, but it doesn't mean that the number has to be somehow contorted to conform to a particular format for the function to work.

0x16 is not distiguished from 22 in any way in any script in any place in AutoIt on any day. "0x16" is a string and it is different from 0x16 and different to 22, but you are not passing a string to _ColorGetRed, you are passing a number. A number represents a quantity and whether you represent the number of cows in a field in hex, binary, octal or whatever it doesn't change the number of cows in the field.

I feel much better now ;)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

martin,

Thank you for that clarification. Like Soulstriker I understood from the Help file that the parameter HAD to be Hex - hence the conversion lesson above. I will raise a ticket for a change in the next release.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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