如何在Java中对BufferedImage进行去饱和处理? [英] How do I desaturate a BufferedImage in Java?

查看:153
本文介绍了如何在Java中对BufferedImage进行去饱和处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最简单的去饱和 BufferedImage 的方法是什么?

What's the simplest way to desaturate a BufferedImage?

推荐答案

使用 ColorConvertOp

public static BufferedImage desaturate(BufferedImage source) {
    ColorConvertOp colorConvert = 
        new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    colorConvert.filter(source, source);

    return source;
}






更新:

确实有一种更简单的方法。您可以使用 GrayFilter 类。这个类有什么好处,它提供了一个静态实用工具方法(即 createDisabledImage(Image i)),它将返回图像的灰显版本


Update :
There is indeed a simpler way. You can use the GrayFilter class. What's nice about this class is that it provides a static utility method (i.e. createDisabledImage(Image i)) that will return a grayed-out version of the image i.

话虽如此,我认为最简单的方法是去饱和 BufferedImage 实例如下:

That being said, I think the simplest way to desaturate a BufferedImage instance is the following:

BufferedImage desaturatedImage = GrayFilter.createDisabledImage(originalImage);

这篇关于如何在Java中对BufferedImage进行去饱和处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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