Making a Single Color Transparent Using MaskData
The Tip on this page is based on the MetaCard 2.4.3 engine.
If you have a version of MetaCard/Revolution that uses an earlier engine than 2.4.3, you can view the original Tip for assistance.
This assumes you have a good understanding of how to manipulate
maskData. If you don’t, take a look at tip
imag003 - Understanding ImageData, MaskData and AlphaData before
The following is an example of creating a single-color transparency of an image much like what is used in GIF images. I have chosen to use pure red (RGB: 255,0,0) as the mask color.
Hope you find this as useful as I did. :-)on mouseUp put the imageData of image 1 into iData put the width of image 1 into tW put the height of image 1 into tH put empty into mData repeat with i = 1 to tH -- iterate each row repeat with j = 1 to tW -- iterate each column -- Get a pointer to the specific end byte of a pixel -- Remember there are 4 bytes per pixel put ((i-1)*tW*4)+(j*4) into tByte -- Go backwards from the end byte to get your R, G and B put charToNum(char (tByte-2) of iData) into tR put charToNum(char (tByte-1) of iData) into tG put charToNum(char (tByte) of iData) into tB if (tR = 255) and (tG = 0) and (tB = 0) then -- pixel is red, mask it put binaryEncode("C",0) after mData else put binaryEncode("C",255) after mData end if end repeat end repeat set the maskData of image 1 to mData set the imageData of image 1 to iData end mouseUp
Posted 7/2/2002 by Ken Ray