将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;
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容