imageData
Rob Cozens
rcozens at pon.net
Sun May 9 10:44:54 EDT 2004
>I'm a little confused about imageData. How would I create an image, using
>imageData, with whatever colors I wanted for each pixel?
>
>Ex: If the new image was 5 pixels by 5 pixels, with each pixel being some
>color that the user chooses, how do I handle imageData to build the final
>image?
Derek,
Per the Dictionary, "Each pixel is represented by four bytes of image
data, with pixels numbered from the top left corner of the image,
left to right, top to bottom. The first byte consists of zeroes, and
the last three bytes encode the amount of red, green, and blue
respectively. ...you can obtain the numeric value of any of the
color channels for a given pixel using the charToNum function. For
example, the numeric value of the red channel for the tenth pixel is
given by the expression, charToNum(char((4*9)+2) of the imageData of
image."
Based on the above (untested):
on changeImageColor imageName,pixelColors
get the imageData of image imageName
put length(it) div 4 into pixelCount
if the number of lines of pixelColors <> pixelCount then \
return "Color list lines & pixel count mismatch."
repeat with x = 1 to pixelCount
put (x-1)*4 into pixelStart
put line x of pixelColors into newColors
put numToChar(item 1 of newColors) into char(pixelStart+2) of it
put numToChar(item 2 of newColors) into char(pixelStart+3) of it
put numToChar(item 3 of newColors) into char(pixelStart+4) of it
end repeat
set the imageData of image imageName to it
return empty -- no error
end changImageColor
Note this assumes you pass a list of the new colors in RGB format,
one line per pixel. You might incorporate a different logic scheme,
perhaps setting the new color based on the value of the original
color.
Hope this helps.
--
Rob Cozens
CCW, Serendipity Software Company
"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."
from "The Triple Foole" by John Donne (1572-1631)
More information about the use-livecode
mailing list