how to make the color image to black and white in Android

后端 未结 2 1869
自闭症患者
自闭症患者 2021-01-17 23:46

I wanted to know the way to convert the color image (which i am downloading from net) to black and white when i am displaying it to the user in android. can anybody found

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 00:12

    Use the built-in methods:

    public static Bitmap toGrayscale(Bitmap srcImage) {
    
        Bitmap bmpGrayscale = Bitmap.createBitmap(srcImage.getWidth(), srcImage.getHeight(), Bitmap.Config.ARGB_8888);
    
        Canvas canvas = new Canvas(bmpGrayscale);
        Paint paint = new Paint();
    
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        canvas.drawBitmap(srcImage, 0, 0, paint);
    
        return bmpGrayscale;
    }
    

提交回复
热议问题