colorMatrix 没有直接处理对比度的方法。
内部有一个 4x5的矩阵数组:
* <pre> * R’ = a*R + b*G + c*B + d*A + e; * G’ = f*R + g*G + h*B + i*A + j; * B’ = k*R + l*G + m*B + n*A + o; * A’ = P*R + q*G + r*B + s*A + t;</pre>
找到 Android-GPUImage 实现
public static final String CONTRAST_FRAGMENT_SHADER = "" + "varying highp vec2 textureCoordinate;\n" + " \n" + " uniform sampler2D inputimageTexture;\n" + " uniform lowp float contrast;\n" + " \n" + " voID main()\n" + " {\n" + " lowp vec4 texturecolor = texture2D(inputimageTexture, textureCoordinate);\n" + " \n" + " gl_Fragcolor = vec4(((texturecolor.rgb - vec3(0.5)) * contrast + vec3(0.5)), texturecolor.w);\n" + " }";
仿照 gl_Fragcolor
来处理:
//对比度范围 [0,2f]val matrix = colorMatrix() //4x5矩阵,rgba+偏移matrix.setScale(lum, lum, lum, 1f)val ary = matrix.arrayary[0] = (ary[0] - 0.5f) * contrast + 0.5fary[1] = (ary[1] - 0.5f) * contrast + 0.5fary[2] = (ary[2] - 0.5f) * contrast + 0.5fary[5] = (ary[5] - 0.5f) * contrast + 0.5fary[6] = (ary[6] - 0.5f) * contrast + 0.5fary[7] = (ary[7] - 0.5f) * contrast + 0.5fary[10] = (ary[10] - 0.5f) * contrast + 0.5fary[11] = (ary[11] - 0.5f) * contrast + 0.5fary[12] = (ary[12] - 0.5f) * contrast + 0.5fpaint.colorFilter = colorMatrixcolorFilter(matrix)
总结 以上是内存溢出为你收集整理的Android - ColorMatrix 处理图像对比度全部内容,希望文章能够帮你解决Android - ColorMatrix 处理图像对比度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)