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 dejhost
      Happy New Year everyone!
      I would like to extract the color values of certain pixels in an image.  This is how I picture the workflow: 
      User opens an image of his choice. Image is shown on the screen. User draws a line into the image. This happens by marking the startpixel and the endpixel of the line The line is drawn, so the user can check visually if he is happy with the line.  The following pixel based properties belonging to the line are stored in Excel: X-Coordinate Y-Coordinate Color Value Additional operations: Extracting for max- and min. color values; Statistical operations.   Browsing through the helpfile of AutoIt I find plenty of functions for treating images (e.g. GDIPlus), but I am completely unsure if Autoit will get me there. Should I read the entire image into an array? Should I rather attempt to script an external image software (e.g. IrfanView, Gimp)?
      I would be very thankful if someone could give some recommendations and maybe list a couple of the most important commands to use.
      Thank you very much.
      Dejhost
       
       
    • By Skeletor
      Hi All,
      While creating a few excel spreadsheets using AutoIt, I came across something which to my limiting time to research the forums I don't anyone has mentioned. 
      The color pallettes are reversed. 
      Huge shock to me.
       
      I wanted to produce a red row but kept on getting blue. 
      Seems like 0xFF0000 was red on the charts but when running the script, I got blue. 
      I then played around with the colors, and after a few tries, I finally got Red. 
      Reversed the FF0000 and the result is 0000FF.
       
      So for Excel compared to Html
      0000FF (Red) - Excel
      0000FF (Blue) - Html

      FFFF00 (Cyan) - Excel
      FFFF00(Yellow) - Html
       
    • By xtcislove
      Hello,
      i stuck again,
      Im using this function to create a treeview from root dir.
       
      ;https://autoit.de/index.php?thread/86082-treeview-root-verbergen/&postID=691139#post691139 #include <File.au3> #include <WindowsConstants.au3> Global $sPath = @ScriptDir Global $hGui = GUICreate('TreeView-Example', 400, 600) Global $idTreeView = GUICtrlCreateTreeView(10, 10, 380, 580, Default, $WS_EX_CLIENTEDGE) GUISetState() _CreatePath($sPath, $idTreeView) Do Until GUIGetMsg() = -3 Func _CreatePath($sPath, $idParent) Local $aFolder, $aFiles, $idItem If StringRight($sPath, 1) <> '\' Then $sPath &= '\' $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS) If Not @error Then For $i = 1 To $aFolder[0] $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent) _CreatePath($sPath & $aFolder[$i], $idItem) Next EndIf $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES) If @error Then Return For $i = 1 To $aFiles[0] $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent) Next EndFunc Folder Structure:

      Folder1
      Folder2
      Folder3
      If a file exists in multiple folders, i like to color it red, if not green. 

      I know how to do this for files, but nut for the folders.

      Because if there is only 1 file in Folder2 that is also in Folder1 that it should only color this single file red, inlcuding its whole tree.

      The Folder1 and Folder2 should be red in this case, too. Other files and trees should stay green.
       
      Edit:
      Basically i like to color a file and its belonging tree red if the file exists more than 1 time.
    • By Ambient
      I have tried several way sto get this to work to no avail. Any help would be appreciated. #include <ListViewConstants.au3> #include <GuiListView.au3> #include "GuiListViewEx.au3" $idItem = GUICtrlCreateListViewItem($r & " | " & $c & $adoRs.Fields("TransactionAmount").value & " | " & $Timestamp & " | " & _StringProper($adoRs.Fields("Tillid").value) & @CRLF & @CRLF & "Card Number : " & $cardnum & " " , $idListView) ConsoleWrite( "IDITEM" & $idItem) If STRINGLEFT($adoRs.Fields("TransactionAmount").value,1)= "-" Then Consolewrite(" String is Negative" & @CRLF) ;Drops in Here as expected ;GUICtrlSetColor(-1, $COLOR_RED) ; Colour line if item is negative this didn' work $TxC= _GUICtrlListView_SetTextColor($hListView, $CLR_RED) ; I also tried $TxC= _GUICtrlListView_SetTextColor(-1, 0xFF0000) CONSOLEWRITE("TEXTCOLOUR RETURNED " & $TxC & @crlf) ; This is returning True ELSE Consolewrite(" String is NOT Negative" & @CRLF) EndIf  
    • By Jefrey
      Needed a way to store global temporary & permanent information and came up with this.
      This is inspired by NodeJS's store and store2 packages, as well as W3 specs' localStorage and sessionStorage, offering multiple ways of usage.
      This is not related to any browser's storage, nor will allow you to access or modify browsers storage - although this is possible and not a hard task, this is not what this UDF is intended to do.
      This UDF offers functions for temporary storage (that gets cleaned up once the application is shutdown) that is kept on memory using ScriptingDictionary, as well as for permanent storage, that is saved on the harddisk as an encrypted file.
      sessionStorage (temporary storage)
      It's useful to keep application state and temporary settings accessible by any part of your script (although it could also be done with a global variable, I still prefer this method).
      You have multiple ways, at your choice, to:
      ; add or modify a key sessionStorage("foo", "bar") store("foo", "bar") sessionStorage_set("foo", "bar") sessionStorage_setItem("foo", "bar") ; read a key (returns false if key does not exist) $read = sessionStorage("foo") $read = store("foo") $read = sessionStorage_get("foo") $read = sessionStorage_getItem("foo") ; delete a key sessionStorage_remove("foo") ; delete all keys sessionStorage_clear() sessionStorage_clearAll() localStorage (permanent storage)
      It's useful to store user-defined settings.
      ; initialize ; this is optional, but allows you to control ; how things are going to be saved localStorage_startup([file where you want the settings to be saved], [crypt password]) ; by default, if not supplied, if supplied the "Default" keyword (or if you dont initialize), ; the file will be a random-named file (based on @ScriptFullPath) at user's %APPDATA% ; and the password will also be based on @ScriptFullPath ; you can set only the crypt password if you want: ; localStorage_startup(Default, "mypassword") ; the usage is the same as sessionStorage ; add or modify a key localStorage("foo", "bar") store2("foo", "bar") ; notice the '2' localStorage_set("foo", "bar") localStorage_setItem("foo", "bar") ; read a key (returns false if key does not exist) $read = localStorage("foo") $read = store2("foo") $read = localStorage_get("foo") $read = localStorage_getItem("foo") ; delete a key localStorage_remove("foo") ; delete all keys localStorage_clear() localStorage_clearAll() Download
×
×
  • Create New...