图像的色调,饱和度,亮度 这三个属性在图像处理中的使用非常的多.并且封装了API来快速调整这些参数.
ColorMatrix颜色矩阵 系统封装的一个类
主要方法:
色调
hueMatrix.setRotate(int axis,float degree)
第一个参数axis系统分别使用了0.1.2来代表Red.Green.Blue三种颜色的处理,第二个参数就是需要处理的值
饱和度
饱和度为0的时候就是灰色的图像
saturation.setSaturation(0);
亮度
三种颜色等比例混合的时候显示白色,当亮度为0的时候,图像变成了黑色的.
lumMatrix.setScale(r,g,b,a);
矩阵的乘法运算
提供了postConcat()来将矩阵的作用效果混合,从而叠加处理效果.
ColorMatrix imageMatrix=new ColorMatrix();
imageMatrix.postConcat(hueMatrix);
imageMatrix.postConcat(saturation);
imageMatrix.postConcat(lumMatrix);
Android颜色矩阵——ColorMatrix
模拟4*5的颜色矩阵,改变其中的值.达到想要的效果
4*5矩阵的布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2" />
<GridLayout
android:id="@+id/group"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:columnCount="5"
android:rowCount="4" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="btnChange"
android:text="@string/change" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="btnReset"
android:text="@string/reset" />
</LinearLayout>
</LinearLayout>
未完待续……
本文介绍了Android中图像处理的核心类ColorMatrix,包括如何通过该类调整图像的色调、饱和度和亮度。并提供了一个4*5颜色矩阵的示例布局文件。
1175

被折叠的 条评论
为什么被折叠?



