babysnails

Help me create an array of colors

6 posts in this topic

Hi.  I started using AutoIt yesterday and right now I'm trying to write my first program. 

I am trying to do the following: 

1) create an array that is the size of a map on a website (in pixels) 

2) populate the array with each corresponding pixel color (hex value) 

3) display the array to make sure it worked

This is what I have so far: 

#include <Array.au3>
$x = WinActivate("Website")

Global $map[510][330] ;the map is 510 pixels wide, 330 pixels tall
Global $mapRows = UBound($map, 1) ;this should be 330
Global $mapCols = UBound($map, 2) ;this should be 510

;ignore the while loop.  it will come into play for me later
;while(1)
   for $i = 0 to $mapCols - 1 ;i think this should iterate over all the pixels that are aligned horizontally across the map
      for $j = 0 to $mapRows - 1 ;same as above but vertically
         $map[$i][$j] = PixelGetColor($i + 305,$j + 29) ;i know that i want to start collecting pixels at (305,29) (this is the top left part of the map)
      Next
   Next

;Exit
;WEnd

_ArrayDisplay($map, "Map", Default, 1)

 

I get this error: 

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$map[$i][$j] = PixelGetColor($i + 305,$j + 29)

To me the statement $map[$i][$j] = PixelGetColor($i + 305,$j + 29) means this (on its first iteration): 

Get the hex value of the pixel at (305,29) and place it in the element which is at the first row and column of the array called map. 

 

Can someone please help me figure out what I am doing wrong here?  

Thanks!

 

Share this post


Link to post
Share on other sites



I get the same, you do have $map[$i][$j] maybe there's a mixup of array variables?

i mean, you use $i and $j and then state those again...

If i was home, i'd try to change the resulting variables

$map[$x][$y] = PixelGetColor

or something.


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

Thank you for the replies.  I tried switching rows and cols and now  do not get an error!  However, when i do this the program doesn't seem to do anything.  

Is there something I need to do after calling  _ArrayDisplay($map, "Map", Default, 1) ?  

Maybe creating this array is just a slow process?

 

Share this post


Link to post
Share on other sites

Sorry for a double post but I dont know how to edit my last post.  It turns out that I did indeed have rows and cols reversed.  

After I fixed this, the reason I wasnt getting any output was that the array was simply too large!  documentation on ArrayDisplay states that the function can output 65525 rows but only 250 columns.  

I am going to go ahead and scale my array back to full size and assume it works after this little experiment.  

Thanks!

 

Share this post


Link to post
Share on other sites

You edit by clicking Edit at bottom of your post. In the area where "Quote" is for all posts.


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

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