NileshSutar Posted September 23, 2013 Share Posted September 23, 2013 (edited) Hi all, i want to create an array that contains pixel colours. I want to scan a client area for all the colors it contains and enter all the colors found(excluding duplicates) in an array called $get_pix.color.So how can i do that?? Edited September 23, 2013 by NileshSutar Link to comment Share on other sites More sharing options...
JohnOne Posted September 23, 2013 Share Posted September 23, 2013 You cannot have a "." in a variable name. They are used as operators in objects. Show what code you have. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
NileshSutar Posted September 23, 2013 Author Share Posted September 23, 2013 You cannot have a "." in a variable name. They are used as operators in objects. Show what code you have The code is : Func start_capture() For $i=$x1 To $x2 Step 1 For $j=$y1 To $y2 Step 1 For $s=0 To <??> Step 1; Don't know how many pixels will be there. What to do? $pixel[$s] = PixelGetColor($i,$j,2) Next Next Next EndFunc Link to comment Share on other sites More sharing options...
JohnOne Posted September 23, 2013 Share Posted September 23, 2013 The area tou are working on should give you the size of the array you need. If the area width is 100 and height is 100, then you need 10000 elements. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
NileshSutar Posted September 23, 2013 Author Share Posted September 23, 2013 The code is : now i have modified it: global $Area=($x2-$x1)*($y2-$y1) global $x1 global $x2 global $y1 global $y2 Func start_capture() For $i=$x1 To $x2 Step 1 For $j=$y1 To $y2 Step 1 For $s=0 To $Area Step 1; Don't know how many pixels will be there. What to do? $pixel[$s] = PixelGetColor($i,$j,2) Next Next Next EndFunc Link to comment Share on other sites More sharing options...
JohnOne Posted September 23, 2013 Share Posted September 23, 2013 (edited) Why not use a 2D array, for example... #include <Array.au3> $Width = 10 $Height = 10 $StartX = 0 $StartY = 0 Local $aPixels[$Height][$Width] For $y = $StartY To $Height -1 For $x = $StartX To $Width -1 $aPixels[$y][$x] = "0x" & Hex(PixelGetColor($x,$y),6) Next Next _ArrayDisplay($aPixels) To make it more generic you need to apply a little maths logic. Edited September 23, 2013 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
NileshSutar Posted September 23, 2013 Author Share Posted September 23, 2013 Why not use a 2D array, for example... #include <Array.au3> $Width = 10 $Height = 10 $StartX = 0 $StartY = 0 Local $aPixels[$Height][$Width] For $y = $StartY To $Height -1 For $x = $StartX To $Width -1 $aPixels[$y][$x] = "0x" & Hex(PixelGetColor($x,$y),6) Next Next _ArrayDisplay($aPixels) To make it more generic you need to apply a little maths logic. i tested the code.I found that the coordinates $StartX and $StartY must be zero for the script to run.Otherwise it will not five results.I figured out why this is happening but i am unable to change the code.So the $y and $x values are not zero when i set $StartX and $StartY to some non-zero.So as they are input to the pixel array the array is getting confused.We should some how set $y=0 and increament its value without affecting PixelGetColor($x,$y). Link to comment Share on other sites More sharing options...
JohnOne Posted September 23, 2013 Share Posted September 23, 2013 Like I said, a little maths logic is all it takes. The start x and y can be whatever you want so long as you as add to it the width and height. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
NileshSutar Posted September 23, 2013 Author Share Posted September 23, 2013 The start x and y can be whatever you want so long as you as add to it the width and height. For $y = $StartY To $Height -1 For $x = $StartX To $Width -1 For $i=0 To ($Width-$StartX+1)*($Height-$StartY+1) +1 $aPixels[$i] = ("0x" & Hex(PixelGetColor($x,$y)) Next Next Next I have made it like that but it is giving me an error "Array variable has incorrect number of subscripts or subscript dimension range exceeded" Link to comment Share on other sites More sharing options...
JohnOne Posted September 23, 2013 Share Posted September 23, 2013 (edited) Look at the for loop, if start y is 300 and height is 20, the loop will be going from 300 to 20. Hint For $y = $StartY To ? + $Height -1 EDIT: Apply reverse logic to your array. Edited September 23, 2013 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
NileshSutar Posted September 23, 2013 Author Share Posted September 23, 2013 (edited) Look at the for loop, if start y is 300 and height is 20, the loop will be going from 300 to 20. Hint For $y = $StartY To ? + $Height -1 EDIT: Apply reverse logic to your array. For $y = $StartY To $StartY + $Height -1;is it right Edited September 23, 2013 by NileshSutar Link to comment Share on other sites More sharing options...
NileshSutar Posted September 23, 2013 Author Share Posted September 23, 2013 (edited) John i think that the thing that is going wrong is the $aPixels[$y][$x] = "0x" & Hex(PixelGetColor($x,$y),6) When $y and $x are zero then there is no problem for $aPixels to take values in.But when $y and $x are non-zero the first element should get 0 index(in array $aPixels) will be told to take $y index which is not zero. I think this is a big problem. Edited September 23, 2013 by NileshSutar Link to comment Share on other sites More sharing options...
JohnOne Posted September 23, 2013 Share Posted September 23, 2013 Off top of my head it'd be something like this #include <Array.au3> $Width = 10 $Height = 10 $StartX = 0 $StartY = 0 Local $aPixels[$Height][$Width] For $y = $StartY To $StartY + $Height -1 For $x = $StartX To $StartX + $Width -1 $aPixels[$y - $StartY][$x - $StartX] = "0x" & Hex(PixelGetColor($x,$y),6) Next Next _ArrayDisplay($aPixels) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
NileshSutar Posted September 23, 2013 Author Share Posted September 23, 2013 Off top of my head it'd be something like this #include <Array.au3> $Width = 10 $Height = 10 $StartX = 0 $StartY = 0 Local $aPixels[$Height][$Width] For $y = $StartY To $StartY + $Height -1 For $x = $StartX To $StartX + $Width -1 $aPixels[$y - $StartY][$x - $StartX] = "0x" & Hex(PixelGetColor($x,$y),6) Next Next _ArrayDisplay($aPixels) lol working. Link to comment Share on other sites More sharing options...
JohnOne Posted September 23, 2013 Share Posted September 23, 2013 Ace. Just pop in a function now and use those non scoped vars as parameters. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
NileshSutar Posted September 23, 2013 Author Share Posted September 23, 2013 Ace. Just pop in a function now and use those non scoped vars as parameters. Yes i did it.VERRY HAPPY. THANKS. 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