AS3:How to change a colored Bitmap's BitmapData to black and white?

前端 未结 7 931
一整个雨季
一整个雨季 2020-12-14 13:35

How can I change the bitmapdata of a coloured Bitmap to Black and White in AS3 ? I\'m developing a simple image editor tool for a CMS in f

7条回答
  •  一向
    一向 (楼主)
    2020-12-14 14:13

    this would be the most elegant solution i presume (with source being you BitmapData):

    const rc:Number = 1/3, gc:Number = 1/3, bc:Number = 1/3;
    source.applyFilter(source.bitmapData, source.bitmapData.rect, new Point(), new ColorMatrixFilter([rc, gc, bc, 0, 0,rc, gc, bc, 0, 0, rc, gc, bc, 0, 0, 0, 0, 0, 1, 0]));
    

    with flash.geom::Point and flash.filters::ColorMaxtrixFilter ...

    ColorMatrixFilter allows many things, such as hue shifts, colorisation, lightening, darkening and desaturation and so on ... otherwise BitmapData::paletteMap and BitmapData::colorTransform are good complements ...

    just wanted to note, that using the following

    const rc:Number = 1/3, gc:Number = 1/2, bc:Number = 1/6; 
    

    looks a little more natural, since subjectively, #00FF00 is brighter than #FF0000, which in turn is brighter than #0000FF

    good luck then ... ;)

    greetz

    back2dos

提交回复
热议问题