CImage:Array
The Array method extracts the pixel data from a CImage into a lua array (table).
tArray = CImage:Array() where |
tArray is a lua array (table) containing all the pixel values of the image.
The following script creates a CImage from a 1-dimensional table, subtracts 0.5 from every element of the table, and then uses the Array method to save the results back into the table:
|
-- make an array (lua table) of data |
|
-- create a new CImage object |
|
-- subtract 0.5 from every pixel (array element) |
|
-- save to the table |
|
-- loop over every table element |
|
-- Print each member |
|
-- result: 1:0.5, 2:2.5, 3:4.5, 4:6.5, 5:8.5 |
Note that the for loop can be compacted to be: for i,v in pairs( I:Array() ) do. However in this form, note that the data are not stored because the lua table is not explicitly assigned.