android 改变bitmap颜色

可能在某些情况下,同一张图片在多个UI上使用,但需要改变的只是图片颜色而且,这种情况你还是不要去打UI MM的主意,不要破坏你在MM心中的所占有率哦!其实用代码就可以搞定的,如下所示:

public static Bitmap tintBitmap(Bitmap inBitmap , int tintColor) {
    if (inBitmap == null) {
        return null;
    }
    Bitmap outBitmap = Bitmap.createBitmap (inBitmap.getWidth(), inBitmap.getHeight() , inBitmap.getConfig());
    Canvas canvas = new Canvas(outBitmap);
    Paint paint = new Paint();
    paint.setColorFilter( new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN)) ;
    canvas.drawBitmap(inBitmap , 0, 0, paint) ;
    return outBitmap ;
}

我建了个微信公众号,我们将每天为您推送优质文章、开源库及学习心得,欢迎关注。

android 改变bitmap颜色_第1张图片
微信公众号.png

你可能感兴趣的:(android 改变bitmap颜色)