Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Generic behavior to check Windows Platform
Marks button, 4 picts with rollover, rolloff
Get VideoForWindows Version
cXtraRTF
AutoCropper v1.2
Custom Alert
Return the name of the current user
DirectSound Xtra
ZGTSB-Bitmap Slider Scroll
Saving Data in Shockwave
 

 

 

Behavior Convert Colour Image to Grayscale

Added on 10/25/2005

 

Compatibilities:
D7 D8 D8_5 D9 Mac PC Script

This item has not yet been rated

Author: Chunick (website)

This will allow the user to convert any colour image to grayscale. There are 4 "modes" to choose from. Test it to discover the differences. The code should be placed in a movieScript.

on grayScaleImg (theImage, theMethod)
grayImage = theImage.duplicate()

Case theMethod of
1:
newImage = image(grayImage.width, grayImage.height, 8, #grayscale)
newImage.copyPixels(grayImage, grayImage.rect, grayImage.rect, [#dither: 1215]) -- 1969, 1215
grayImage = newImage

2:
newImage = image(grayImage.width, grayImage.height, 8, #grayscale)
newImage.copyPixels(grayImage, grayImage.rect, grayImage.rect, [#dither: 1969])
grayImage = newImage

3:
theWidth = grayImage.width - 1
theHeight = grayImage.height - 1
repeat with x = 0 to theWidth
repeat with y = 0 to theHeight
theColour = grayImage.getPixel(point(x,y))
-- commented out one is not as rich, but brings out more detail, potentially
-- grayComp = (0.2980 * theColour.red) + (0.5882 * theColour.green) + (0.1138 * theColour.blue)
-- the below uses these fractions: 54/255 R, 182.5/255 G, 18.5/255 B
grayComp = (0.2125 * theColour.red) + (0.7154 * theColour.green) + (0.0721 * theColour.blue)
grayImage.setPixel(point(x,y), color(grayComp, grayComp, grayComp))
end repeat
end repeat

4:
theWidth = grayImage.width - 1
theHeight = grayImage.height - 1
repeat with x = 0 to theWidth
repeat with y = 0 to theHeight
theColour = grayImage.getPixel(point(x,y))
-- not as rich, but brings out more detail, potentially
-- uses these fractions: 76/255 R, 150/255 G, 29/255 B
grayComp = (0.2980 * theColour.red) + (0.5882 * theColour.green) + (0.1138 * theColour.blue)
grayImage.setPixel(point(x,y), color(grayComp, grayComp, grayComp))
end repeat
end repeat

end Case

return grayImage
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail