Soulstriker Posted December 26, 2009 Share Posted December 26, 2009 (edited) 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 December 28, 2009 by Soulstriker Link to comment Share on other sites More sharing options...
Malkey Posted December 26, 2009 Share Posted December 26, 2009 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 More sharing options...
Moderators Melba23 Posted December 26, 2009 Moderators Share Posted December 26, 2009 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. 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 ) 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Soulstriker Posted December 28, 2009 Author Share Posted December 28, 2009 (edited) 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 December 28, 2009 by Soulstriker Link to comment Share on other sites More sharing options...
martin Posted December 28, 2009 Share Posted December 28, 2009 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 More sharing options...
Soulstriker Posted December 28, 2009 Author Share Posted December 28, 2009 Hahahah, yeah! That's exactly the code that i tried and it worked!As you say, I read the help file and I thought that I must transform the value to Hex.Then I thought "what if..." and it worked!Thank you for your comment! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 28, 2009 Moderators Share Posted December 28, 2009 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Soulstriker Posted December 28, 2009 Author Share Posted December 28, 2009 Any help with this new topic? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now