如何着色位图以纯色 [英] How to tint a Bitmap to a solid color

查看:150
本文介绍了如何着色位图以纯色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个人怎么会去着色位图以纯色,有效地取代有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);

这篇关于如何着色位图以纯色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆