Jump to content
Sign in to follow this  
chacoya121

plz help store color in array!

Recommended Posts

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

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

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

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

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

  • Similar Content

    • By Tony007
      Hi,
      is it possible to export only the area "$idOutput" with the TEXT as a PNG?
      Thanks
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Example() Func Example() Local $hGUI = GUICreate("Test", 700, 700, -1, -1) Local $input1 = GUICtrlCreateInput("", 10, 10, 150, 20) Local $idButtonStart = GUICtrlCreateButton("Start", 200, 10, 50, 30) Local $idButtonClear = GUICtrlCreateButton("Clear", 260, 10, 50, 30) Local $idButtonExport = GUICtrlCreateButton("Export", 320, 10, 50, 30) Local $idOutput = GUICtrlCreateLabel("TEXT", 10, 50, 500, 500, BitOR($BS_PUSHLIKE, $SS_CENTER)) GUICtrlSetFont($idOutput, 45, 800, "", "Impact") GUISetState(@SW_SHOW, $hGUI) ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButtonStart $ContentInput1 = GUICtrlRead($input1) GUICtrlSetData($idOutput, $ContentInput1) Case $idButtonClear GUICtrlSetData($input1, "") GUICtrlSetData($idOutput, "") Case $idButtonExport EndSwitch WEnd GUIDelete($hGUI) Exit EndFunc ;==>Example  
    • By argumentum
      ..I'm coding the High Contrast theme editor and using the _ChooseColor() I wandered why it does not keep the the custom colors I've added.
      Found that adding a static declaration would do it. But why stop there. Why not keep going, So I put this together that is non code braking ( backwards compatible ), to replace the one in <Misc.au3>
      _ChooseColor_mod_Example() Func _ChooseColor_mod_Example() Local $aCustColors[17] $aCustColors[1] = 0xFF0000 $aCustColors[16] = 0x0000FF $aCustColors = _ChooseColor_mod(2, "0x00ff00", 2, 0, $aCustColors) ConsoleWrite(@CRLF & $aCustColors[0] & @CRLF & @CRLF) ConsoleWrite(@CRLF & _ChooseColor_mod(2, $aCustColors[0], 2, 0, $aCustColors)[0] & @CRLF & @CRLF) ConsoleWrite(@CRLF & _ChooseColor_mod(2, "0x00ff00", 2) & @CRLF & @CRLF) ; just as default behaviour ConsoleWrite(@CRLF & _ChooseColor_mod(2, "0x00ff00", 2, 0, 'reset as is neither "Default" nor "Array[17]"') & @CRLF & @CRLF) ; just as default behaviour EndFunc ;==>_ChooseColor_mod_Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ChooseColor_mod ; Description ...: ; Syntax ........: _ChooseColor_mod([$iReturnType = 0[, $iColorRef = 0[, $iRefType = 0[, $hWndOwnder = 0[, $vCustColors = Default]]]]]) ; Parameters ....: $iReturnType - [optional] an integer value. Default is 0. See remarks for values. ; $iColorRef - [optional] an integer value. Default is 0. ; $iRefType - [optional] an integer value. Default is 0. See remarks for values. ; $hWndOwnder - [optional] a handle to the parent window. Default is 0. ; $vCustColors - [optional] an array of colors to show as custom values. See remarks for values. ; Return values .: Success - Hex value of the selected color ; Failure - $vCustomColors is returned if set, otherwise, -1 is returned. Also sets @error: ; | -2 - User initialized $tagCustcolors via $vCustColors. ; | -3 - User canceled or invalid dll struct. ; | -4 - Invalid $iReturnType value. ; | Other - Error returned from Dll call. ; Author ........: Gary Frost (gafrost) ; Modified ......: argumentum ; Remarks .......: $iReturnType can be 0 (RGB COLORREF), 1 (Hex BGR), or 2 (Hex RGB). ; $iRefType can be 0 (ColorRef), 1 (BGR Hex), or 2 (RGB Hex). ; $vCustColors is a zero based array[17] where: ; index 0 hold the color returned by the function. ; index 1 to 16 are the colors to use in Custom colors in RGB. ; One can pass the array with array[0] = -2 to initialize the custom colors without loading the interface. ; When $vCustColors is used, it returns the modified array. ( not the color as integer ). ; Anything other than Default or a proper array, will clear $tagCustcolors ( holder of the custom colors ). ; When $vCustColors is omited or Default, $tagCustcolors is kept ( hence, no need for the array to keep custom colors ). ; Related .......: Same Func from <Misc.au3> ; Link ..........: https://www.autoitscript.com/forum/topic/200985-_choosecolor-but-better/ ; Example .......: YES ; =============================================================================================================================== Func _ChooseColor_mod($iReturnType = 0, $iColorRef = 0, $iRefType = 0, $hWndOwnder = 0, $vCustColors = Default) ; basic code from Misc.au3 ; https://www.autoitscript.com/forum/topic/200985-_choosecolor-but-better/ ; added here for independance of #include <Misc.au3> Local Static $tagCHOOSECOLOR = "dword Size;hwnd hWndOwnder;handle hInstance;dword rgbResult;ptr CustColors;dword Flags;lparam lCustData;" & _ "ptr lpfnHook;ptr lpTemplateName" Local Static $__MISCCONSTANT_CC_ANYCOLOR = 0x0100 Local Static $__MISCCONSTANT_CC_FULLOPEN = 0x0002 Local Static $__MISCCONSTANT_CC_RGBINIT = 0x0001 ; added here for independance of #include <Misc.au3> Local $vReturn, $bCustColors = False, $tagCustcolors = "dword[16]" Local $tChoose = DllStructCreate($tagCHOOSECOLOR) Local Static $tCc = DllStructCreate($tagCustcolors) ; added Static (mod.), to keep $tagCustcolors changes by user when called again. If $vCustColors == Default Then ; nothing ElseIf UBound($vCustColors) = 17 Then $bCustColors = True For $n = 1 To 16 DllStructSetData($tCc, 1, $vCustColors[$n], $n) Next Else $tCc = DllStructCreate($tagCustcolors) ; reset, just in case you'd want to have it default again EndIf If $iRefType = 1 Then ; BGR hex color to colorref $iColorRef = Int($iColorRef) ElseIf $iRefType = 2 Then ; RGB hex color to colorref $iColorRef = Hex(String($iColorRef), 6) $iColorRef = '0x' & StringMid($iColorRef, 5, 2) & StringMid($iColorRef, 3, 2) & StringMid($iColorRef, 1, 2) EndIf DllStructSetData($tChoose, "Size", DllStructGetSize($tChoose)) DllStructSetData($tChoose, "hWndOwnder", $hWndOwnder) DllStructSetData($tChoose, "rgbResult", $iColorRef) DllStructSetData($tChoose, "CustColors", DllStructGetPtr($tCc)) DllStructSetData($tChoose, "Flags", BitOR($__MISCCONSTANT_CC_ANYCOLOR, $__MISCCONSTANT_CC_FULLOPEN, $__MISCCONSTANT_CC_RGBINIT)) Local $aResult = DllCall("comdlg32.dll", "bool", "ChooseColor", "struct*", $tChoose) If @error Then If Not $bCustColors Then Return SetError(@error, @extended, -1) Else $vCustColors[0] = -1 Return SetError(@error, @extended, $vCustColors) EndIf EndIf If $bCustColors Then ; this here is better than at the end, For $n = 1 To 16 ; that way you'll get the custom colors anyway. $vCustColors[$n] = DllStructGetData($tCc, 1, $n) Next If $vCustColors[0] = -2 Then Return $vCustColors EndIf If $aResult[0] = 0 Then ; Return SetError(-3, -3, -1) ; user selected cancel or struct settings incorrect If Not $bCustColors Then Return SetError(-3, -3, -1) Else $vCustColors[0] = -1 Return SetError(-3, -3, $vCustColors) EndIf EndIf Local $sColor_picked = DllStructGetData($tChoose, "rgbResult") If $iReturnType = 1 Then ; return Hex BGR Color $vReturn = '0x' & Hex(String($sColor_picked), 6) ElseIf $iReturnType = 2 Then ; return Hex RGB Color $sColor_picked = Hex(String($sColor_picked), 6) $vReturn = '0x' & StringMid($sColor_picked, 5, 2) & StringMid($sColor_picked, 3, 2) & StringMid($sColor_picked, 1, 2) ElseIf $iReturnType = 0 Then ; return RGB COLORREF $vReturn = $sColor_picked Else $vReturn = -1 SetError(-4, -4) EndIf If Not $bCustColors Then Return $vReturn $vCustColors[0] = $vReturn Return $vCustColors EndFunc ;==>_ChooseColor_mod Hopefully will replace the default one in the next release 
    • By vargheseg
      I am new to AutoIT but I do use Sikuli.  Decided to use AutoIT for  this project as all  the required can be created in an .exe file, does not  need Java like Sikuli.
      Also  which can be pushed to tool bar of Windows 10 desktop.
      Our users will interact with a client/server application and normally work on dual screen. The script needs to detect the c/s application from the dual screen,  needs to do three mouse clicks based of image/pixel comparison, will need to wait till the  click object is available and then finally take screen capture  of the top 40 rows  and save the .jpeg file to  windows file share location.
      once the file save is completed,  pop up message - the screen capture is completed. Then the users can do their regular work.
      Potentially  other factor that will play are the screen resolution.
      Can anyone guide me to some relevant scripts already in the forum. In the meantime I am learning  the basics of the  tool.
       
      Appreciate feedback and any help
      George V
       
       
    • By DannyJ
      Hello Forum, 
      I have one special Combo-box [with BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE) ] and if I press one button I want to change the Combo-box's background color, and after I press Button B I want to change it to the basic settings and it not works.
      I wanna do this with one combo-box.
      I have already tried several methods and I tried  GUICtrlComboSetColors that I have found on this forum.
      (But this methods works perfectly with Cobo boxes that don't have BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE). 
      Here is the example code
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= ;$CBS_DROPDOWNLIST ;$GUI_SS_DEFAULT_COMBO $Form1 = GUICreate("Form1", 504, 249, 252, 227) $Combo1 = GUICtrlCreateCombo("", 136, 24, 193, 25,BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; I want to change this special combo's background color if I press button 1 $Button1 = GUICtrlCreateButton("Button1", 112, 96, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 264, 96, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Combo1," " & "|" & "apple" & "|" & "banana" & "|" & "cherry" ," ") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetBkColor($Combo1,0x0078D7) Case $Button2 ;Makes the original bc color GUICtrlSetBkColor($Combo1,0xFFFFFF) EndSwitch WEnd  
      Thanks you in advance your help
    • By user4157124
      ConsoleWrite('>Message here.' & @CRLF) outputs colored text (per + > - ! characters).
      ConsoleWrite('warning' & @TAB & '38' & @TAB & 'more text ...' & @CRLF) enables jump to line 38 on doubleclick.

      Using "jump to line" format, only red and pink text coloring seems possible (simply prefixing color directives to output-text disables jump to line functionality). Is it possible to combine the two (define custom color while keeping "jump to line" functionality)?
×
×
  • Create New...