Sign in to follow this  
Followers 0
chacoya121

plz help store color in array!

11 posts in this topic

#1 ·  Posted (edited)

Local $count = 1
    Local $x1= 100,$y1 = 100,$x2 = 110,$y2 = 110
    $area = ($x2+$x1)*($y2+$y1)
    Local $array[$area][2]
    For $i = $x1 to $x2 Step 1
        For $j = $y1 to $y2 Step 1
            $color = PixelGetColor($i,$j)
            $scolor = Hex($color,6)
            $array[$count][2] = [$scolor,1]
            $position = _ArraySearch($array,$scolor,0,0,0,0,1)
            If $array[$position][0] = $scolor Then
                $array[$position][1] +=1
            Else
                $count += 1
            EndIf
        Next
    Next
    _ArrayDisplay($array)

plz help adjust and shrink it down soo confusing playing with array

Edited by chacoya121

Share this post


Link to post
Share on other sites



#2 ·  Posted

Where is all of your code? This is confusing init of itself... what are you trying to do exactly?

Share this post


Link to post
Share on other sites

#3 ·  Posted

get color and store in array

Share this post


Link to post
Share on other sites

#5 ·  Posted

Here is one of many possible array formats.

#include <Array.au3>

Local $x1 = 120, $y1 = 100, $x2 = 130, $y2 = 110
Local $array[($x2 - $x1 + 1)][($y2 - $y1 + 1)]
For $i = 0 To ($x2 - $x1)
    For $j = 0 To $y2 - $y1
        $array[$j][$i] = $i + $x1 & "," & $j + $y1 & "=" & "0x" & Hex(PixelGetColor($i + $x1, $j + $y1), 6)
    Next
Next
_ArrayDisplay($array, "Coordinates(X,Y)=PixelColor")

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

can you add up all the duplicate color

and test with some different coordinate it wont work

Local $x1 = 77, $y1 = 214, $x2 = 118, $y2 = 254

is there limit to array it could stored?

Edited by chacoya121

Share this post


Link to post
Share on other sites

#7 ·  Posted

From here you will find:-
    16,777,216 - Maximum number of elements for an array.

Although, the _ArrayDisplay() function does not display that many elements.

And, another example.

#include <Array.au3>

$a = _ArrayColors(120, 100, 130, 110) ; Default ($iRet = 2) returns both arrays,
_ArrayDisplay($a[0]) ; 2D Array of colors at their coordinates.
_ArrayDisplay($a[1]) ; 2D array of colors and the number of occurrences of that color.

$b = _ArrayColors(77, 214, 118, 254, 0) ; $iRet = 0 Returns array of colors at their coordinates only.
_ArrayDisplay($b)


Func _ArrayColors($x1, $y1, $x2, $y2, $iRet = 2)
    Local $array[($y2 - $y1 + 1)][($x2 - $x1 + 1)]
    Local $aUniqueArray[0][2], $iIndex
    For $i = 0 To ($x2 - $x1)
        For $j = 0 To $y2 - $y1
            If $iRet <> 1 Then $array[$j][$i] = $i + $x1 & "," & $j + $y1 & "=" & "0x" & Hex(PixelGetColor($i + $x1, $j + $y1), 6)
            $iIndex = _ArraySearch($aUniqueArray, "0x" & Hex(PixelGetColor($i + $x1, $j + $y1), 6))
            If $iRet Then
                If $iIndex = -1 Then
                    _ArrayAdd($aUniqueArray, "0x" & Hex(PixelGetColor($i + $x1, $j + $y1), 6) & "|" & 1)
                Else
                    $aUniqueArray[$iIndex][1] += 1
                EndIf
            EndIf
        Next
    Next
    Switch $iRet
        Case 0
            Return $array
        Case 1
            Return $aUniqueArray
        Case 2
            Local $r[] = [$array, $aUniqueArray]
            Return $r
    EndSwitch
EndFunc   ;==>_ArrayColors

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Global $x1 = 82
Global $y1 = 217
Global $x2 = 115
Global $y2 = 255
Func _Start()
    For $i = $x1 To $x2 Step 1
        For $j = $y1 To $y2 Step 1
            $color = PixelGetColor($i, $j)
            $getini = IniReadSection("Color Code.ini", "Color")
            If Not @error Then
                IniWrite("Color Code.ini", "Color",Hex($color, 6), $getini[1][1]+1)
            ElseIf @error Then
                IniWrite("Color Code.ini", "Color",Hex($color, 6), "1")
            EndIf
        Next
    Next
EndFunc   ;==>Start

thank you , you are the best ,i understand it now

can you put that into ini file

i try similar way but some how doesn't work

sorry for my english and low lvl programming

Quote
Quote

 

 

 

Edited by chacoya121

Share this post


Link to post
Share on other sites

#9 ·  Posted

A few points for your consideration:-
- You have to call a function for it to actually run, like using "_Start()".

The next two are not wrong,  just not conventionally used:-
- When using For - Next loops, "Step 1" is the default, so if  "Step 1" is absent, "Step 1" is assumed.
- This "ElseIf @error Then" can be replaced with just "Else",  because, when starting the If statement with "If Not @error Then" one should realize any following "Else" will be logically mutually exclusive.  Meaning there can be only two possible conditions either an error, or, not an error.
Often, the "Else" is used to cover all conditions that are not covered by the preceding "If" or "ElseIf's".  
This related note of interest comes to mind.  In AutoIt:  False is equal to zero, (0).   True is everything else that is not equal to zero, (0) - numerically speaking. (Ref: Booleans)

Global $x1 = 82
Global $y1 = 217
Global $x2 = 115
Global $y2 = 255

_Start()

ShellExecute("Color Code.ini") ; View Color Code.ini file.


Func _Start()
    If FileExists("Color Code.ini") Then FileDelete("Color Code.ini") ; Prevent adding extra color occurrences to existing ini file
    For $i = $x1 To $x2
        For $j = $y1 To $y2
            $color = PixelGetColor($i, $j)
            $getini = IniReadSection("Color Code.ini", "Color")
            If Not @error Then
                IniWrite("Color Code.ini", "Color", Hex($color, 6), $getini[1][1] + 1)
            Else
                IniWrite("Color Code.ini", "Color", Hex($color, 6), "1")
            EndIf
        Next
    Next
EndFunc   ;==>_Start

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Global $x1 = 82
Global $y1 = 217
Global $x2 = 115
Global $y2 = 255
_Start()

ShellExecute("Color Code.ini") ; View Color Code.ini file.

Func _Start()
    If FileExists("Color Code.ini") Then FileDelete("Color Code.ini")
    For $i = $x1 To $x2 Step 1
        For $j = $y1 To $y2 Step 1
            $color = PixelGetColor($i, $j)
            $getini = IniReadSection("Color Code.ini", "Color")
            If @error Then IniWrite("Color Code.ini", "Color", "0x" & Hex($color, 6),"")
            If Not @error Then IniWrite ("Color Code.ini", "Color", "0x" & Hex($color, 6), "")
            For $k = 0 To $getini[0][0] Step 1
                If $getini[$k][0] = Hex($color,6) Then
                    $getini[1][1] += 1
                EndIf
            Next
        Next
    Next

EndFunc   ;==>Start

plz help me add duplicate color

Edited by chacoya121

Share this post


Link to post
Share on other sites

#11 ·  Posted

On 6/1/2017 at 2:53 AM, chacoya121 said:

....

plz help me add duplicate color

My script of post #9,  writes the color to "Color Code.ini" file.   Look at that file and you should see the color in hexi-decimal without the prefix "0x" and the color equals the number of times that pixel color appears in the search rectangle.

Example of  "Color Code.ini" file.

[Color]
C0C0C0=1242
C0C0A0=978
C0C085=978
854600=889
C0A067=978
C08546=968
672300=882
672346=986
460000=924
464685=1001
2367A0=990
462367=898
466767=898
.... Etc

 

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

  • Similar Content

    • AndyS19
      By AndyS19
      I have a listview with 3 columns and I want to set the 3rd column's color based on the item's 'Param' value, but even though I set up for the 3rd column, the entire row always gets the color.
      My test code is below, but here is the pertinent code:
      Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg
      Here is the full test code:
      #include-once ;#cs #NoTrayIcon #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_UseX64=N Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("_test_exit") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase #include <GuiListBox.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> Global $__MCP_obj, $__MCP_GUI_hWnd, $idListView, $hListView Global $hMainWin test() Exit Func test() $hMainWin = GUICreate("Test window", 120, 100, @DesktopWidth / 2, -1) GUICtrlCreateButton("Hwnd", 10, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_1stTEST_btn") GUICtrlCreateButton("ID", 50, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_2ndTEST_btn") GUISetOnEvent($GUI_EVENT_CLOSE, "_test_exit") GUISetState(@SW_SHOW) While (1) Sleep(17) WEnd EndFunc ;==>test Func _myColorPicker($obj) logmsg("+++: $obj = 0x" & Hex($obj) & @CRLF) Local $flags = 0 Local $ww, $wh, $x, $y, $w, $h $__MCP_obj = $obj $ww = 350 $wh = 500 $x = 200 $y = 150 $__MCP_GUI_hWnd = GUICreate("myColorPicker", $ww, $wh, $x, $y, $flags) $x = 10 $y = 10 $w = 150 $h = 20 GUICtrlCreateButton("Set caller's color", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_SetColor_btn") $y += $h + 5 $w = $ww - 25 $h = $wh - 100 $idListView = GUICtrlCreateListView("", $x, $y, $w, $h, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($idListView) $x = $ww / 2 - 50 $y = $wh - 60 $w = 100 $h = 25 GUICtrlCreateButton("Quit Popup", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_QUIT_btn") GUICtrlSetFont($idListView, 8.5, -1, -1, "courier new") _GUICtrlListView_AddColumn($idListView, "Name", 100) _GUICtrlListView_AddColumn($idListView, "Value", 100) _GUICtrlListView_AddColumn($idListView, "Sample", 100) _GUICtrlListView_SetColumnWidth($idListView, 0, 100) _GUICtrlListView_SetColumnWidth($idListView, 1, 80) logmsg("+++: $idListView = " & $idListView) logmsg("+++: $hListView = 0x" & Hex($hListView)) __MCP_populateListView($hListView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $__MCP_GUI_hWnd) EndFunc ;==>_myColorPicker Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg Func __MCP_exit() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_exit Func __MCP_handle_SetColor_btn() If (IsHWnd($__MCP_obj)) Then GUISetBkColor($COLOR_BLUE, $__MCP_obj) Else GUICtrlSetBkColor($__MCP_obj, $COLOR_BLUE) EndIf EndFunc ;==>__MCP_handle_SetColor_btn Func __MCP_populateListView($hWnd) Local $text, $parts, $iIndex Local Static $aItems[] = [ _ "BLACK | " & $CLR_BLACK & "|" & "", _ "BLUE | " & $CLR_BLUE & "|" & "", _ "RED | " & $CLR_RED & "|" & "", _ "WHITE | " & $CLR_WHITE & "|" & "", _ "YELLOW | " & $CLR_YELLOW & "|" & "" _ ] _GUICtrlListView_BeginUpdate($hWnd) _GUICtrlListView_DeleteAllItems($hWnd) For $ndx = 0 To UBound($aItems) - 1 $text = $aItems[$ndx] $parts = StringSplit($text, "|", 2) $parts[0] = StringStripWS($parts[0], 3) $parts[2] = StringStripWS($parts[2], 3) $iIndex = _GUICtrlListView_AddItem($hWnd, $parts[0], -1, $parts[1]) _GUICtrlListView_AddSubItem($hWnd, $iIndex, Hex($parts[1]), 1) _GUICtrlListView_AddSubItem($hWnd, $iIndex, $parts[0], 2) Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==>__MCP_populateListView Func __MCP_handle_QUIT_btn() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_handle_QUIT_btn Func handle_1stTEST_btn() _myColorPicker($hMainWin) EndFunc ;==>handle_1stTEST_btn Func handle_2ndTEST_btn() _myColorPicker(@GUI_CtrlId) EndFunc ;==>handle_2ndTEST_btn Func _test_exit() Exit EndFunc ;==>_test_exit  
    • astrionn
      By astrionn
      So I had this Idea of creating a tooltip which shows me my ping.
      That itself was made quickly and I thought too add a couple features.
      I want the tooltip background to be a different color depending on the ping. (good ping is green, medium ping is yellow,...)
      So how do I color in a tooltip? google brought me to this: 
       
      where in the comments I found this:
      $s = "LOW" ToolTip($s, 0, 0, "Battery Information");, $icon) $H_TOOLTIP1 = WinGetHandle($s) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $H_TOOLTIP1, "wstr", "", "wstr", "") DllCall("user32.dll", "int", "SendMessage", "hwnd", $H_TOOLTIP1, "int", 1043, "int", 2552550, "int", 0) Sleep(1000) Which I then used in my code with different color codes... Trial and Error brought me these that I wanted to use:
       
      The Problem is if I loop through my code it only sets the color for the 1st loop and then sticks to it.
      The real problem is tho that I don't exactly understand the dllcalls... And I guess that's why it isn't working
      So if someone would be so awesome to explain to me how they work, or at least can give me a list of these parameters then I would really appreciate that and learn something new
      Obviously a solution to my problem is awesome aswell ^^
      I run this under Windows 8.1
      There is my code in a paste.
      https://pastebin.com/q525f7mS
    • cosmos
      By cosmos
      I must be missing something but I can't seem to work out how to open the standard Windows Color dialog box?
      Basically the equivalent of InputBox but for colors (so that the user can select a color). I think there are some external UDFs for this, but are there any ways of doing it with included UDFs, standard AutoIt functions or interfacing with Windows directly?
      Usage info: I'm making a database-like program and there are Categories (which work similar to Tables), and the user will be able to select unique colors for Categories so when they display multiple Categories at once (like displaying multiple Tables with similar columns in one list ) they can easily differentiate the Categories at quick glance.
      Thanks!
    • Miliardsto
      By Miliardsto
      Hello i have problem with function PixelGetColor. On my computer it working fine but in some cases it not working.
      And Im clicking on the active window on red color and it give me the same color still. But in other computers when clicking on the same color red it gives other values and returned color in MsgBox is not red.
      Dont know is it a real main thing what causing problem but,
      I noticed that problem was on one windows 10.
      I have windows 8 and working well. On other windows 10 works well to
      Maybe it is caused by windows aero or something like that
      How to deal with it?
      There is a code
      HotKeySet("{PAUSE}", "MouseCord") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func MouseCord() Global $MousePos = MouseGetPos() $clickedColor = PixelGetColor($MousePos[0], $MousePos[1]) MsgBox(0, "Done", $clickedColor) EndFunc  
       
    • SalamanderSoup
      By SalamanderSoup
      I've created a simple script that opens the Snipping Tool; Selects the "Full Screen Snip" option; then closes the program, prompting a save.  What I can't figure is how to name the file using the system date and time.
      Can anyone help?
      Run(@WindowsDir & '\system32\SnippingTool.exe') AutoItSetOption('MouseCoordMode', 0) Sleep(1) $hWnd= WinWait("Snipping Tool", "ToolBarWindow32", 1) WinActive($hWnd) MouseClick('primary', 84, 48, 1, 0) MouseClick('primary', 84, 140, 1, 0) WinClose("[Class:Microsoft-Windows-Tablet-SnipperEditor]") ControlClick("Snipping Tool", "", "Button1")