imageData

Dar Scott dsc at swcp.com
Sun May 9 14:18:38 EDT 2004


On Sunday, May 9, 2004, at 05:20 AM, Webmaster - Dreamscape Software 
wrote:

> I'm a little confused about imageData.  How would I create an image, 
> using
> imageData, with whatever colors I wanted for each pixel?

The image is a sequence of pixel values in row and column order.  The 
pixels of the topmost row are first.  Within each row, the pixels are 
left-to-right.

The sequence is binary, that is, your value string should be 
interpreted as a sequence of bytes.  Each four bytes or characters 
represent a pixel.  The first byte of the pixel data is zero.  The next 
three bytes represent the RGB value, one byte for each color component. 
  Each color component is represented by a number from 0 to 255.  
Extract it with charToNum() and build it with numToChar().  (Note:  
Because some images have image-wide color settings such as gamma, two 
images with the same pixel value might not display the same, but see 
setting method below.)

At this time, using 'put ... into ...' for each pixel or color 
component to build imageData values can be slow.  Try to use 'put ... 
after ...'.  That is, do this when you can build your imageData from 
front to back.  (There is an enhancement request in for a feature that 
will help.)

If you change the size or shape of the image, you must handle that when 
you set the imageData.

Here is one way:

   set the text of me to empty
   set the height of me to pHeight
   set the width of me to pWidth
   set the imageData of me to pImageData

Using crop might also work.

Dar Scott



More information about the use-livecode mailing list