我正在创建位图,接下来我正在绘制第二个纯色位图.
现在我想改变第一个位图,所以我画的纯色将是透明的.
现在我想改变第一个位图,所以我画的纯色将是透明的.
或者简单地说,我想从位图中删除一种颜色的所有像素.
我匆匆尝试过每个彩色滤镜,并且xfermode没有运气,还有其他可能性去除其他颜色逐像素的颜色吗?
解决方法
这适用于从位图中删除某种颜色.主要部分是使用AvoidXfermode.如果尝试将一种颜色更改为另一种颜色,它也应该工作.
我应该补充说,这回答了从位图中移除颜色的问题标题.具体的问题可能更好地解决了使用PorterDuff Xfermode像OP所说.
// start with a Bitmap bmp // make a mutable copy and a canvas from this mutable bitmap Bitmap mb = bmp.copy(Bitmap.Config.ARGB_8888,true); Canvas c = new Canvas(mb); // get the int for the colour which needs to be removed Paint p = new Paint(); p.setARGB(255,255,0); // ARGB for the color,in this case red int removeColor = p.getColor(); // store this color's int for later use // Next,set the alpha of the paint to transparent so the color can be removed. // This could also be non-transparent and be used to turn one color into another color p.setAlpha(0); // then,set the Xfermode of the pain to AvoidXfermode // removeColor is the color that will be replaced with the pain't color // 0 is the tolerance (in this case,only the color to be removed is targetted) // Mode.TARGET means pixels with color the same as removeColor are drawn on p.setXfermode(new AvoidXfermode(removeColor,AvoidXfermode.Mode.TARGET)); // draw transparent on the "brown" pixels c.drawPaint(p); // mb should now have transparent pixels where they were red before