概念
偶然机会要给一个图片添加一个蒙层,半透明-淡淡的雾状效果。于是用到setColorFilter,这个颜色过滤器使用到了android.graphics.PorterDuff.Mode ,于是去官网看下具体使用。很多文章把tint解释为着色。
- Tint: 着色,就是当前设置的颜色和原目标关联,形成最终的UI效果。
- Mode:原数据和目标数据它们之间处于什么样的关系。
String tint = ”#44ffffff“;
img.setColorFilter(Color.parseColor(tint) );
图解
蓝色是原图片,红色目标图片
1. add
Adds the source pixels to the destination pixels and saturates the result.
添加原数据到目标数据,且重叠部分饱和颜色、
2. clear
Destination pixels covered by the source are cleared to 0.
清除所有
2. DARKEN
Retains the smallest component of the source and destination pixels.
保留两者最小的颜色分量
2. DST
The source pixels are discarded, leaving the destination intact.
保留目标像素
2. DST_ATOP
Discards the destination pixels that are not covered by source pixels.
丢失没有被原数据覆盖的部分像素
2.DST_IN
Keeps the destination pixels that cover source pixels, discards the remaining source and destination pixels.
保留覆盖原数据的目标像素,丢弃其他。
2. DST_OUT
Keeps the destination pixels that are not covered by source pixels.
保留没有被原数据覆盖的像素
2. DST_OVER
The source pixels are drawn behind the destination pixels.
原数据在目标数据后面
2. LIGHTEN
Retains the largest component of the source and destination pixel.
保留两者最大的颜色分量
2. MULTIPLY
Multiplies the source and destination pixels.
混合重叠像素
2. OVERLAY
Multiplies or screens the source and destination depending on the destination color.
混合两种
2. SCREEN
Adds the source and destination pixels, then subtracts the source pixels multiplied by the destination.
2. SRC
The source pixels replace the destination pixels.
2. SRC_ATOP
Discards the source pixels that do not cover destination pixels.
2. SRC_IN
Keeps the source pixels that cover the destination pixels, discards the remaining source and destination pixels.
2. SRC_OUT
Keeps the source pixels that do not cover destination pixels.
2. SRC_OVER
The source pixels are drawn over the destination pixels.
2. XOR
Discards the source and destination pixels where source pixels cover destination pixels.