图片的亮度,饱和度设置


参考文章:https://www.jianshu.com/p/69f62882e6a8

最后代码设置如下

//获取图片的亮度
float alpha=getImgAlpha(context);
Paint paint=new Paint();
Canvas canvas=new Canvas(copyBitmap);
ColorMatrix colorMatrixL=new ColorMatrix();
colorMatrixL.setScale(alpha, alpha, alpha, 1);
ColorMatrix colorMatriximg=new ColorMatrix();
colorMatriximg.postConcat(colorMatrixL);
ColorMatrixColorFilter colorMatrixColorFilter=new ColorMatrixColorFilter(colorMatriximg);
paint.setColorFilter(colorMatrixColorFilter);
canvas.drawBitmap(bm,new Matrix(),paint);
return copyBitmap;

后面参考这个
http://www.bnee.net/article/1441251.html

最后的出的代码如下

public static Bitmap handleImageEffect(Bitmap bitmap,float lum) {
    //传进来的bitmap默认不能修改  所以再创建一个bm
    Bitmap bm = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    //画布
    Canvas canvas = new Canvas(bm);
    //抗锯齿
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    //修改亮度
    ColorMatrix lumMatrix = new ColorMatrix();
    //r g b a    1 表示全不透明
    lumMatrix.setScale(lum, lum, lum, 1);
    //组合Matrix
    ColorMatrix imageMatrix = new ColorMatrix();
    imageMatrix.postConcat(lumMatrix);
    //为画笔设置颜色过滤器
    paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix));
    //在canvas上照着bitmap画
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return bm;
}

文章作者: 小游
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 小游 !
  目录