Specifies the binary data that makes up the picture in an image object.
set the imageData of <image> to <binaryData>
put the imageData of image ID 3577 into dateToAnalyze
set the imageData of the mouseControl to the personalImage of this card
Use the imageData property to process an image and display the processed version.
The imageData consists of the picture data presented in a standard form. The form of the imageData property, unlike the content, does not depend on what format the image is recorded in; it's always in the same form, which specifies the color of each pixel in the image, four bytes per pixel.
Each pixel is represented by 32 bits (4 bytes) of image data, with pixels numbered from the top left corner of the image, left to right, then top to bottom. The first byte consists of zeros, and the last three bytes encode the amount of red, green, and blue respectively.
Since each pixel is represented by 4 bytes, you can obtain the numeric value of any of the color channels for a given pixel using the byteToNum function (or CharToNum). For example, this is how you might extract the color channel values from the 10th pixel of an image:
put the imageData of image 1 into tData put 10 - 1 into tOffset -- Pixel positions start at 0 put byteToNum(byte ((4 * tOffset) + 2) of tData) into tRed put byteToNum(byte ((4 * tOffset) + 3) of tData) into tGreen put byteToNum(byte ((4 * tOffset) + 4) of tData) into tBlue
When changing the imageData property, make sure the new data is the correct size: 4 bytes per pixel in the image. If you set an image's imageData property to data whose total length is incorrect, the image appearance will be distorted.
The imageData property is related to the content of the image --changing either one changes what's displayed in the image --but they're not identical: the imageData property and the image content are in different forms, have different sizes, and include overlapping but not identical information about the picture.
The imageData, unlike the contents of the image container, is based on the picture as it's presented on the screen, not stored in the image object. This means that if you resize an image, the content of the image does not change, but its imageData does. If you create an image and then reduce its size, its imageData reflects the scaled-down, displayed image, not the original full-scale image. If you create a second image and set its imageData property to the imageData of the original image, resizing the first image back to the original dimensions displays the original image at full resolution, but resizing the second image does not, because setting its imageData transferred only the scaled-down version of the original.
This code is legal to change the imageData of an image (after changing its rect, for example):
set the imageData of image myImage to the imageData of image myImage
put image "Full Resolution" into image "Copied Image"
Since the imageData of an image is binary rather than text, trying to display the data in a field may cause unexpected behavior.
You cannot load format-specific (GIF, PNG, JPG, etc) binary images using 'set the imageData'. You should instead use the "put" command, as an extrapolation of the "Full resolution" tip above.
For example, let's say you have an image file "Forest.png" and you decide that you don't want to 'import from file'. You could instead do the following:
put URL "binfile:Forest.png" into tImageData put tImageData into image "Image Viewer"
This has several ancillary benefits over imageData as well:
- Failing to set the height and width of the target image before importation will not cause graphical corruption.
- Formatted images are usually considerably more compact than the raw imageData.