安卓饱和度滤镜矩阵

标签 android filter matrix imagefilter

我已经为饱和度编写了以下矩阵,但它没有给出正确的结果。有人能告诉我这里有什么问题吗?

   ColorMatrix colorMatrix = new ColorMatrix(saturationFilter(0.3f));
   ColorMatrixColorFilter matrix = new ColorMatrixColorFilter(colorMatrix);

    public static float[] saturationFilter(float x){

    float lumR = 0.3086f;
    float lumG = 0.6094f;
    float lumB = 0.0820f;
    float matrix[] = {lumR*(1-x)+x,lumG*(1-x),lumB*(1-x), 0, 0, 0,0,
                      lumR*(1-x)+x,lumG*(1-x),lumB*(1-x), 0, 0, 0,0,
                      lumR*(1-x)+x,lumG*(1-x),lumB*(1-x), 0, 0, 0,0,
                      0f, 0f, 0f, 1f, 0f,
                      0f ,0f, 0f, 0f ,1f};

    return matrix;
}

最佳答案

我已经通过正确编写矩阵来更正上述函数,因为我在所有错误的情况下都增加了红色 channel 。这工作正常。

   public static float[] saturationFilter(float saturation){

    float p_val = cleanValue(saturation,100);
    float x = 1+((p_val > 0) ? 3*p_val/100 : p_val/100);
    float lumR = 0.3086f;
    float lumG = 0.6094f;
    float lumB = 0.0820f;
    float matrix[] = {lumR*(1-x)+x, lumG*(1-x),  lumB*(1-x), 0, 0, 
                      lumR*(1-x),   lumG*(1-x)+x, lumB*(1-x), 0, 0,
                      lumR*(1-x),   lumG*(1-x),   lumB*(1-x)+x, 0, 0,
                      0f, 0f, 0f, 1f, 0f,
                      0f ,0f, 0f, 0f ,1f};

    return matrix;
   }

     private static float cleanValue(float p_val, float p_limit){
         return Math.min(p_limit, Math.max(-p_limit, p_val));
}

关于安卓饱和度滤镜矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12582288/

相关文章:

matlab - 读取 MATLAB 中的值并将坐标分配给条目

Matlab低通滤波器输出初值/终值

c - ANSI C - 右上三角矩阵的数值稳定回代算法

android - 配置 : error: C compiler cannot create executables when configuring for Android

java - 如何从 CustomAdapter 将 textColor 设置为 edittext

PHP:文件到数组检查和替换

javascript - 在javascript中过滤对象数组中的数组

python - 如何使 numpy 数组列总和为 1

android - 如何让我的安卓模拟器使用我电脑的 VPN 接口(interface)?

java - 多个 Activity 在单个布局中进行更改