AS3:如何将彩色位图的位图数据更改为黑白?
如何在 AS3 中将彩色位图的位图数据更改为黑白? 我正在为 Flash 中的 CMS 开发一个简单的图像编辑器工具。
人们应该能够将上传的位图的颜色切换为黑白。 我希望位图数据本身发生变化因此我可以随后使用 Adobe 的 JPGEncoder 类将其写入 ByteArray。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这将是我认为最优雅的解决方案(
source
是您的BitmapData
):使用
flash.geom::Point
和flash .filters::ColorMaxtrixFilter
...ColorMatrixFilter
允许做很多事情,例如色调偏移、着色、增亮、变暗和去饱和度等等...否则BitmapData::paletteMap
和BitmapData::colorTransform
是很好的补充...只是想指出,使用以下内容
看起来更自然一点,因为主观上,
#00FF00
是比#FF0000
更亮,而#FF0000
又比#0000FF
更亮,祝你好运...;)
greetz
back2dos
this would be the most elegant solution i presume (with
source
being youBitmapData
):with
flash.geom::Point
andflash.filters::ColorMaxtrixFilter
...ColorMatrixFilter
allows many things, such as hue shifts, colorisation, lightening, darkening and desaturation and so on ... otherwiseBitmapData::paletteMap
andBitmapData::colorTransform
are good complements ...just wanted to note, that using the following
looks a little more natural, since subjectively,
#00FF00
is brighter than#FF0000
, which in turn is brighter than#0000FF
good luck then ... ;)
greetz
back2dos
好吧,只需使用 getPixel 和 setPixel,并对颜色进行平均(我确信可能还有另一种方法可以使用滤镜或其他方法来实现此目的):
Well, just using getPixel and setPixel, and averaging the colors (I'm sure there may be another way to do this with a filter or something):
实际上,您可以以更简单的方式使用 back2dos 的解决方案:
其中 mc 是 MovieClip 或 Sprite 容器,其中位图数据作为视觉元素存在。
谢谢 back2dos :)
actually, you can use back2dos 's solution in a much easier way:
where mc is the MovieClip or Sprite container where the bitmapdata exists as a visual element.
thanks back2dos :)
谢谢饼干,
复制原始位图数据确实是恢复颜色的最简单的解决方案。
Thanks Cookie,
Copying the original bitmapdata was indeed the easiest solution to restore color.
我用这个剪刀:
I use this snipper:
我尝试了两种方法。
看起来 ColorMatrixFilter 方法在处理大图像时工作得更快。
有没有什么方法可以去除过滤器? 或者我应该再次更改 ColorMatrixFilter 值吗?
I tried both methods.
Seems like the ColorMatrixFilter method works a lot faster when working with large images.
Is there some method to remove the Filter too? or shoud I change the ColorMatrixFilter values again?
感谢您的方法,我创建了一个小工具,可以让您使用这些值:
http://bjornson.inhb.de/?p=159
初始值是Macke 提出:RGB 为 30%、59% 和 11%。
您还可以加载外部图像并尝试获得图像的最佳效果。
Thank you for the approach, I created a small tool, that lets you play around with the values:
http://bjornson.inhb.de/?p=159
The initial values are the ones proposed by macke: 30%, 59% and 11% for rgb.
You can also load external images and try out for the best result for your images.