-
Notifications
You must be signed in to change notification settings - Fork 28
Enumerate Pixels Using For Loops
Edison Hua edited this page Jun 11, 2024
·
13 revisions
Only on AutoHotkey version 2
Enumerates all the pixels in the image.
pic := ImagePutBuffer("https://picsum.photos/2/3") ; 2 x 3 pixel image
pic.show(1) ; or ImagePutWindow(pic)
for color in pic ; Enumerate a single value
MsgBox color ; Get color
The output depends on the number of parameters passed to the for-loop.
- A 1-parameter
for color in pic
returns only the ARGB pixel - And the 3-parameter
for x, y, color in pic
returns the x, y coordinate as well.
- color - The color is an ARGB unsigned 32-bit integer with 256 values for each color channel.
- x, y - Yields (x, y) coordinates sequentially.
- x, y, color - The [x, y] coordinates denote the current x, y position of the color.
- Invalid number of parameters.
- Invalid number of parameters.
- x, y, color, red, green, blue - The red, green, blue represents the individual color channel and ranges from 0-255.
- x, y, color, red, green, blue, alpha - The alpha represents the alpha channel.
; Use this code to load the pic variable.
pic := ImagePutBuffer("https://picsum.photos/2/3") ; 2 x 3 pixel image
pic.show(1) ; or ImagePutWindow(pic)
The 1-parameter for-loop returns only the ARGB pixel.
for color in pic
MsgBox color
The 2-parameter example
for x, y in pic
pic[x, y] := 0xFF0000 ; Sets the x, y to red.
The 3-parameter for-loop returns the x, y coordinate and the ARGB pixel.
for x, y, color in pic
pic[x, y] := 0xFF0000 ; Sets the x, y to red.
The 6-parameter for-loop returns the x, y coordinate, the ARGB pixel, and the red, green, and blue components.
for x, y, color, red, green, blue in pic
MsgBox x ", " y
. "`n" c
. "`n" r ", " g ", " b
The 7-parameter for-loop returns the x, y coordinate, the ARGB pixel, and the red, green, blue, and alpha channel components.
for x, y, color, red, green, blue, alpha in pic
MsgBox x ", " y
. "`n" c
. "`n" r ", " g ", " b ", " a