java - Android滤镜,改变可绘制颜色

标签 java android image layout imagefilter

所以,我想对 Android 中的图像应用滤镜,该图像全是绿色,但具有不同的色调,我想将其设为红色。现在我正在使用这段代码:

Drawable ballon = ContextCompat.getDrawable(context, R.drawable.msg_out);
        ballon.setColorFilter(new
                PorterDuffColorFilter(context.getResources().getColor(R.color.redLightClose), PorterDuff.Mode.MULTIPLY));

view.setBackgroundDrawable(ballon);

但结果我得到了两种颜色的棕色混合......我应该使用另一种过滤器吗?如果是这样,您会推荐一个女巫。

最佳答案

我使用 Tint 代替,它完成了工作。

Drawable iconDrawable = ContextCompat.getDrawable(context, R.drawable.msg_out);
            DrawableCompat.setTint(iconDrawable, context.getResources().getColor(R.color.primary));
            setBackgroundViewCompat(text, iconDrawable);

关于java - Android滤镜,改变可绘制颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31817773/

相关文章:

java - 列出 jar 文件中的 xml 文件

android - 如何判断 Activity 已经被通知区域覆盖?

python - 使用另一个列表 python 从列表创建索引值数组

html - 为什么我的 <img> 元素的堆栈顺序相反?

java - 在检索图像时已为此响应调用 getOutputStream()

Java 后端 : REST, 通过 Google 登录进行身份验证,现在怎么办?

java - 使用 SharedPreferences 保存复选框,java

java - 如何添加 float 但将总数保持/包装在 0..1 范围内?

android - Codenameone 本地 map 离线?

python - OpenCV关闭特定键上的窗口?