读书人

android替图片去色,返回灰度图片

发布时间: 2012-09-09 09:27:54 作者: rapoo

android为图片去色,返回灰度图片

就是大家喜闻乐见的图片去色,返回黑白的图片,具体的方法就是为bitmap添加colorFilter,废话不多说了,上代码:

 public static Bitmap getGreyImage(Bitmap old) {               int width, height;               height = old.getHeight();               width = old.getWidth();                   Bitmap new= Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);               Canvas c = new Canvas(old);               Paint paint = new Paint();               ColorMatrix cm = new ColorMatrix();               cm.setSaturation(0);               ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);               paint.setColorFilter(f);               c.drawBitmap(new, 0, 0, paint);               return new;           }   

?

读书人网 >Android

热点推荐