AS3:如何将彩色 Bitmap 的 BitmapData 更改为黑白? [英] AS3:How to change a colored Bitmap's BitmapData to black and white?

查看:32
本文介绍了AS3:如何将彩色 Bitmap 的 BitmapData 更改为黑白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 AS3 中将彩色位图的位图数据更改为 黑白?我正在为 Flash 中的 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.

人们应该能够将上传的位图的颜色切换为黑白.我希望位图数据本身发生变化 所以我可以在之后使用 Adob​​e 的 JPGEncoder 类将其写入 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.

推荐答案

这将是我认为最优雅的解决方案(source 就是你 BitmapData):

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::Pointflash.filters::ColorMaxtrixFilter ...

ColorMatrixFilter 允许许多事情,例如色调偏移、着色、变亮、变暗和去饱和等等......否则 BitmapData::paletteMapBitmapData::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 ...

只是想注意,使用以下内容

just wanted to note, that using the following

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

祝你好运……;)

问候

back2dos

这篇关于AS3:如何将彩色 Bitmap 的 BitmapData 更改为黑白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆