ColorUtil.java 文件源码

java
阅读 43 收藏 0 点赞 0 评论 0

项目:AmenEye 作者:
/**
 * 混合两种颜色的色值
 * Blend {@code color1} and {@code color2} using the given ratio.
 *
 * @param ratio of which to blend. 0.0 will return {@code color1}, 0.5 will give an even blend,
 *              1.0 will return {@code color2}.
 */
public static
@CheckResult
@ColorInt
int blendColors(@ColorInt int color1,
                @ColorInt int color2,
                @FloatRange(from = 0f, to = 1f) float ratio) {
    final float inverseRatio = 1f - ratio;
    float a = (Color.alpha(color1) * inverseRatio) + (Color.alpha(color2) * ratio);
    float r = (Color.red(color1) * inverseRatio) + (Color.red(color2) * ratio);
    float g = (Color.green(color1) * inverseRatio) + (Color.green(color2) * ratio);
    float b = (Color.blue(color1) * inverseRatio) + (Color.blue(color2) * ratio);
    return Color.argb((int) a, (int) r, (int) g, (int) b);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号