ColorMatrixColorFilter颜色过滤(离线用户的灰色头像处理)

来源:互联网 发布:淘宝用的什么数据库 编辑:程序博客网 时间:2024/04/30 15:47
Android的图片资源默认是静态的,单实例;如果两个IM好友的头像一样,最简单的都是用的软件自带头像,有一个在线,一个离线,直接改变头像的灰度,则两个用户的头像都会变灰或者在线,答案是:Drawable.mutate()。 
Java代码  收藏代码
  1. Drawable mDrawable = context.getResources().getDrawable(R.drawable.face_icon);     
  2. //Make this drawable mutable.     
  3. //A mutable drawable is guaranteed to not share its state with any other drawable.     
  4. mDrawable.mutate();     
  5. ColorMatrix cm = new ColorMatrix();     
  6. cm.setSaturation(0);     
  7. ColorMatrixColorFilter cf = new ColorMatrixColorFilter(cm);     
  8. mDrawable.setColorFilter(cf);    
原创粉丝点击