Grayscale Converter

Answering to CK

1.
ck said,

January 14, 2008 @ 8:07 pm · Edit

… you mentioned to use BitmapData.paletteMap() to generate a grayscale image. Until now I didn’t get this working. How did you do that?

You can convert a BitmapData to Grayscale easily without using my ColorUtils class.

import br.hellokeita.utils.ColorUtils;

var bmpData:BitmapData = new BitmapData(w, h);

var grayscaleArray:Array = new Array();
var c:Number;
for(var i = 0; i < 0xff; i++){
       
        c = i * .3 + i * .59 + i * .11;
        grayscaleArray[i] = (c<<16) + (c<<8) + c;
       
}

bmpData.paletteMap(bmpData, bmpData.rect, new Point(0,0), grayscaleArray, grayscaleArray, grayscaleArray);

Leave a Comment