一个人怎么会去着色位图以纯色,有效地取代有alpha> 0到给定RGB值的所有像素?除了如何做同样的事情,但保持阿尔法每个像素?我不是在寻找的每个像素的操作,因为他们往往是缓慢的。
How would one go about tinting a Bitmap to a solid color, effectively replacing all pixels that have an alpha > 0 to a given RGB value? In addition how to do the same thing, but keeping the alpha for every pixel? I'm not looking for per-pixel operations as they tend to be slow.
我试图用一个ColorMatrixColorFilter和ColorFilter,该做的着色位图,但它们上色执行100%的色彩代替。
I tried using a ColorMatrixColorFilter and a ColorFilter, which do tint the Bitmap, but they colorize instead of performing a 100% tint.
我解决了这个用PorterDuffColorFilter
I solved this by using a PorterDuffColorFilter
Paint paint = new Paint();
paint.setColorFilter(new PorterDuffColorFilter(targetColor, PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(resource, matrix, paint);