合并两个ColorMatrix或在Imageview上同时应用两个或更多ColorMatrix [英] Merge Two ColorMatrix or Apply two or more ColorMatrix simultaneously on Imageview

查看:201
本文介绍了合并两个ColorMatrix或在Imageview上同时应用两个或更多ColorMatrix的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在改变ImageView的亮度,对比度,饱和度和色调。我已经搜索了很多。

I am changing Brightness, Contrast, Saturation and Hue of an ImageView. I have searched lot on it.

我得到了一些适用于 ColorMatrix的代码。

[1。] 对于亮度,ColorMatrix就像

[1.] For Brightness ColorMatrix is some thing like

    float brightness = (-50F * 1.5F);
    ColorMatrix cmB = new ColorMatrix();
    cmB.set(new float[] { 1, 0, 0, 0, brightness,
    0, 1, 0, 0,brightness,
    0, 0, 1, 0, brightness,
    0, 0, 0, 1, 0 });
    myImageView.setColorFilter(new ColorMatrixColorFilter(cmB));

正常运作。

[2。] 对于对比度,ColorMatrix是不同,也可以正常使用。

[2.] For Contrast ColorMatrix is something Different, which also works properly.

但是,所有这些ColorMatrix都可以单独使用。意味着最后应用的ColorMatrix的效果只是ImageView上的场景,因为它完全正确,删除先前应用的 ColorMatrix的效果,并且最后一次应用ColorMatrix。

BUT, all these ColorMatrix works individually. Means the effect of last applied ColorMatrix is only scene on ImageView, because it does exactly it, which removes effect of earlier applied ColorMatrix and setups last applies ColorMatrix.

现在我想合并或混合所有同时的ColorMatrix。意味着想要对ColorMatrix of Brightnrs / Saturation / Hue的效果应用ColorMatrix of Contrast。

Now I want to MERGE or mix-up ColorMatrix of All Simultaneously. Means want to apply ColorMatrix of Contrast on the effect of ColorMatrix of Brightnrs / Saturation / Hue.

推荐答案

如果你想应用两个颜色矩阵,只需将它们相乘即可。

If you want to apply two color matrices, just multiply them together.

如果你有颜色矩阵A和颜色矩阵B,然后:

If you have color matrix A, and color matrix B, then :

C = B * A;
outpixel = C * inpixel 

相当于

outpixel = B * A * inpixel

编辑

我刚注意到那些是5x4矩阵(最初我认为它们是4x4)。由于你不能直接乘以它们,我认为在乘法之前将两个矩阵添加第5个标识行(0,0,0,0,1)是合适的(使它们都为5x5),并在之后丢弃第5行乘以。

I just noticed that those are 5x4 matrices (originally I thought they were 4x4). Since you can't multiply them directly, I think would be appropriate to add a 5th identity row (0,0,0,0,1) to both matrices before multiplying (to make them both 5x5), and discard the 5th row after multiplying.

这篇关于合并两个ColorMatrix或在Imageview上同时应用两个或更多ColorMatrix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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