Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android位图掩码颜色,删除颜色大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创建位图,接下来我正在绘制第二个纯色位图.
现在我想改变第一个位图,所以我画的纯色将是透明的.

或者简单地说,我想从位图中删除一种颜色的所有像素.
我匆匆尝试过每个彩色滤镜,并且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

大佬总结

以上是大佬教程为你收集整理的Android位图掩码颜色,删除颜色全部内容,希望文章能够帮你解决Android位图掩码颜色,删除颜色所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。