如何获得一种到另一种的中间颜色? [英] How to get intermediate colors from one to another?

查看:120
本文介绍了如何获得一种到另一种的中间颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
基于百分比的两种颜色之间的android颜色?
如何找到两种颜色之间的所有颜色?

Possible Duplicate:
android color between two colors, based on percentage?
How to find all the colors between two colors?

一开始,我们有RGB的两种颜色和一个数字,以表示它们之间的中间颜色.方法必须返回具有所需颜色的数组.强烈需要有关算法的帮助.

At the beginning, we have two colors in RGB, and a number, for the intermediate colors between them. Method must return an array with required colors. Strongly need help with an algorithm.

推荐答案

假设我们有2种颜色(R1,G1,B1)(R2,G2,B2)和N种中间颜色:

Suppose we have 2 Colors (R1,G1,B1) (R2,G2,B2) and N number of intermediate colors:

for i from 1 to N:
    Ri = R1 + (R2-R1) * i / N
    Bi = B1 + (B2-B1) * i / N
    Gi = G1 + (G2-G1) * i / N
    AddToArray(Ri,Gi,Bi)

您正在寻找什么吗?

PS:如果您想要更自然的颜色渐变,建议使用HSL颜色空间而不是RGB.

PS: I would recommend using the HSL color space instead of the RGB if you want to have a more natural color gradient.

这篇关于如何获得一种到另一种的中间颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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