通过调整亮度嘉洛斯 [英] Adjusting Lightness using ColorMatrix

查看:147
本文介绍了通过调整亮度嘉洛斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调整图像的亮度使用嘉洛斯,但我失去了其值修改才达到(试图调整色相,明度也和亮度是两个不同的功能时,你可以看到在Photoshop这个选项)这一点。

I'm trying to adjust the lightness of an image (You can see this option in Photoshop when trying to adjust the Hue, also lightness and brightness are two different features) using ColorMatrix but am lost on which values to change to achive this.

目前我能够使用这种code键更改色相

Currently I'm able to change the Hue using this code

public static void adjustHue(ColorMatrix cm, float value)
    {
        value = cleanValue(value, 180f) / 180f * (float) Math.PI;
        if (value == 0)
        {
            return;
        }
        float cosVal = (float) Math.cos(value);
        float sinVal = (float) Math.sin(value);
        float lumR = 0.213f;
        float lumG = 0.715f;
        float lumB = 0.072f;
        float[] mat = new float[]
        { 
                lumR + cosVal * (1 - lumR) + sinVal * (-lumR), lumG + cosVal * (-lumG) + sinVal * (-lumG), lumB + cosVal * (-lumB) + sinVal * (1 - lumB), 0, 0, 
                lumR + cosVal * (-lumR) + sinVal * (0.143f), lumG + cosVal * (1 - lumG) + sinVal * (0.140f), lumB + cosVal * (-lumB) + sinVal * (-0.283f), 0, 0,
                lumR + cosVal * (-lumR) + sinVal * (-(1 - lumR)), lumG + cosVal * (-lumG) + sinVal * (lumG), lumB + cosVal * (1 - lumB) + sinVal * (lumB), 0, 0, 
                0f, 0f, 0f, 1f, 0f, 
                0f, 0f, 0f, 0f, 1f };
        cm.postConcat(new ColorMatrix(mat));
    }

我想了解关于如何使用嘉洛斯来改变亮度以相同的方式。如果实现这一目标的任何其他方式,我很开放的解决方案:)

I want to understand on how to use the colormatrix to change the lightness in the same way. If there is any other way of achieving this, I'm open for solutions :)

推荐答案

Ok..So我终于想通了这一点。

Ok..So I finally figured this out.

明度可以使用PorterDuffColorFilter类来调节

Lightness can be adjusted using the PorterDuffColorFilter Class

下面是我使用方法

public static PorterDuffColorFilter applyLightness(int progress) {

    if(progress>0)
    {
        int value = (int) progress*255/100;
        return new PorterDuffColorFilter(Color.argb(value, 255, 255, 255), Mode.SRC_OVER);
    } else {
        int value = (int) (progress*-1)*255/100;
        return new PorterDuffColorFilter(Color.argb(value, 0, 0, 0), Mode.SRC_ATOP);
    }

}

进步的价值为-100(黑色)到100(亮)

The value of progress is from -100 (dark) to 100(bright)

只是传递值在Photoshop中此方法。你得到的过滤器可以用颜料和画布使用。

Just pass the values as in photoshop to this method. The filter that you get can be used with paint and canvas.

希望这可以帮助别人。

这篇关于通过调整亮度嘉洛斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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