Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

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

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 flash.

People should be able to switch the colour of the uploaded Bitmap to black and white. I want the bitmapdata itself to change So I can write it to a ByteArray with Adobe's JPGEncoder Class afterwards.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...