色彩矩陣
要想實(shí)現(xiàn)Android圖像特效處理需要了解色彩矩陣:
色彩處理需要三個(gè)方面調(diào)整圖片顏色:
1、色調(diào)-------------物體傳播的顏色
2、飽和度--------------------顏色的純度
3、亮度-------------------顏色的相對(duì)明暗
Android系統(tǒng)封裝了ColorMatrix類,通過這個(gè)類可以很簡(jiǎn)單通過修改矩陣值來修改圖片顏色效果。
實(shí)例化:
ColorMatrix colorMatrix =newColorMatrix();
1、setRotate(int axis,float degree)設(shè)置色調(diào),參數(shù)一用0、1、2代表red、Green、Blue三種顏色,參數(shù)二表示需要處理的值;
2、setSaturation(float sat)設(shè)置顏色飽和度,參數(shù)表示飽和度值,參數(shù)為0就是灰色頭像了
3、setScale(foat lum,float lum,float lum,1)設(shè)置亮度,當(dāng)lum為0時(shí),圖片就變?yōu)楹谏?/p>
4.postConcat()方法將矩陣效果混合,從而疊加處理效果。
效果展示:


附上代碼:
**
* Created by MSI on 2017/6/21.
*/
public class GrayPicture {
Bitmap bitmap;
/**
*
*@param btm 需要變色的圖片
*@param mHue 色調(diào)值,該出默認(rèn)為0
*@param mStauration 飽和度值,該出默認(rèn)為0
*@param mLum 亮度值,該出默認(rèn)為1,亮度值為0則會(huì)出現(xiàn)黑屏
*/
public Bitmap setBitmap(Bitmap btm,floatmHue,floatmStauration ,floatmLum){
ColorMatrix colorMatrix =newColorMatrix();
colorMatrix.setRotate(0, mHue);
colorMatrix.setRotate(1, mHue);
colorMatrix.setRotate(2, mHue);
ColorMatrix colorMatrix1 =newColorMatrix();
colorMatrix1.setSaturation(mStauration);
ColorMatrix colorMatrix2 =newColorMatrix();
//? ? ? ? colorMatrix2.setScale(mLum, mLum, mLum, 1);
colorMatrix2.setScale(1,1,1,1);
ColorMatrix colorMatrixs =newColorMatrix();
colorMatrixs.postConcat(colorMatrix);
colorMatrixs.postConcat(colorMatrix1);
colorMatrixs.postConcat(colorMatrix2);
bitmap= Bitmap.createBitmap(btm.getWidth(), btm.getHeight(), Bitmap.Config.ARGB_8888);
finalPaint paint =newPaint();
paint.setAntiAlias(true);
Canvas canvas =newCanvas(bitmap);
paint.setColorFilter(newColorMatrixColorFilter(colorMatrixs));
canvas.drawBitmap(btm,0,0, paint);
returnbitmap;
}
}