将Bitmap中某个颜色替换成其他颜色

使用ARGB(255,0,0,0)也就是黑色替换bitmap中的0x616161,容忍度为50范围的颜色

private Bitmap handleCrossImageBack(Bitmap crossimage){
         // start with a Bitmap bmp
        Bitmap newBmp = crossimage.copy(Bitmap.Config.ARGB_8888, true);
        Canvas c = new Canvas(newBmp);

        // get the int for the colour which needs to be removed
        Paint paint = new Paint();// 去锯齿
        paint.setAntiAlias(true);// 防抖动
        paint.setDither(true);// 图像过滤
        paint.setFilterBitmap(true);
        paint.setARGB(255, 0, 0, 0); // ARGB for the color to replace,black replace gray
        paint.setXfermode(new AvoidXfermode(0x616161, 50, AvoidXfermode.Mode.TARGET));
        c.drawPaint(paint);
        return newBmp;
    }

你可能感兴趣的:(将Bitmap中某个颜色替换成其他颜色)