ActionScript 3 Greyscale
Just had to desaturate a clip and then return it to normal. Code wise it’s rather simple, the following turns a MovieClip with an instance name of test to grey:
// Make Grey
var matrix:Array = ;
matrix = matrix.concat([r, g, b, 0, 0]);// red
matrix = matrix.concat([r, g, b, 0, 0]);// green
matrix = matrix.concat([r, g, b, 0, 0]);// blue
matrix = matrix.concat([0, 0, 0, 1, 0]);// alpha
test.filters = [new ColorMatrixFilter(matrix)];
To return it to the default state just clear the color matrix:
// Return to normal
test.filters = [new ColorMatrixFilter()];
Thanks alot for this David, I was attempting to convert to a bitmap and apply thesholds. Now theres no need and its so simple.
Great tip, but shouldn’t the numbers be red= 0.299, green = 0.587, blue = 0.114 (International Telecommunications Union Standard)?
This blog mentions it: http://jswidget.com/blog/tag/grayscale-image/
Ah, that does sound good. I’m not sure where I got the original values from. I did a search for them and it seems there’s alot of people doing the same thing. If I use this again then I’ll use the values you indicated.
The original values used by David are from the BT709 standard published by ITU-R (International Telecommunication Union). The values provided by Nick are from the NTSC and PAL standards.