AS3:如何更改颜色的位图的的BitmapData以黑人和白人? [英] AS3:How to change a colored Bitmap's BitmapData to black and white?
问题描述
我如何更改 AS3的彩色位图的为黑白这两个BitmapData STRONG>? 我正在开发一个简单的图片编辑工具,一个CMS闪光灯。
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.
人们应该能够上传的位图的颜色转换为黑色和白色。 我想这两个BitmapData本身改变这样我就可以把它写入与Adobe的JPGEn codeR类的ByteArray之后。
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.
推荐答案
这将是最完美的解决方案我presume(与源
是你的BitmapData code>):
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]));
与 flash.geom ::点
和 flash.filters使用:: ColorMaxtrixFilter
...
的ColorMatrixFilter
让很多事情,如色调的变化,colorisation,减轻,变暗和饱和度等...否则的BitmapData :: paletteMap
和的BitmapData ::的ColorTransform
是很好的补充......
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 ...
只是想注意,使用以下
const rc:Number = 1/3, gc:Number = 1/2, bc:Number = 1/6;
看起来多了几分自然的,因为主观上,#00FF00
比#FF0000
,这又是光明的比#0000FF
looks a little more natural, since subjectively, #00FF00
is brighter than #FF0000
, which in turn is brighter than #0000FF
吉祥话......)
这篇关于AS3:如何更改颜色的位图的的BitmapData以黑人和白人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!