如何解决如何混合具有不同体积和化学性质的多种颜色?
我找到了How to mix two int colors,并希望能够将多种颜色混合成不同的体积。专业人士众所周知,混合颜色取决于颜色的体积,但也取决于告诉颜色如何混合的参数。 由于化学反应,相同颜色的两个不同品牌的混合方式不同。分光光度计将显示 red1 + blue1 混合物和 red2 + blue2 混合物之间的差异,具体取决于每种成分的颜料特性。 因此,我们必须使用参数'prop',该参数给出每种颜色品牌相对于其他颜色品牌的相对混合能力。
String[] colors = {"#BFD000","#F36285","#F0EBE2","#0066c1"};
float[] ratios = {1f,2f,3f,1.5f};
float[] props = {.7f,.32f,.43f,.15f};
让我们将这四种颜色混合在一起:1份#BFD000与2份#F36285,依此类推...
String blend(String[] colors,float[] ratios,float[] props)) {
int size = colors.length;
int alpha = 0,red = 0,green = 0,blue = 0;
float totalRatio = 0f;
for(int i = 0; i < size; i++) totalRatio = totalRatio + ratios[i];
for(int i = 0; i < size; i++) {
Color strColor = Color.decode(colors[i]);
alpha = (int)(alpha + (strColor.getRGB() >> 24 & 0xff) * (ratios[i]/totalRatio) * props[i]);
red = (int)(red + ((strColor.getRGB() & 0xff0000) >> 16) * (ratios[i]/totalRatio)* props[i]);
green = (int)(green + ((strColor.getRGB() & 0xff00) >> 8) * (ratios[i]/totalRatio)* props[i]);
blue = (int)( blue + (strColor.getRGB() & 0xff) * (ratios[i]/totalRatio)* props[i]);
}
Color color = new Color( alpha << 24 | red << 16 | green << 8 | blue );
String hex = String.format("#%02x%02x%02x",color.getRed(),color.getGreen(),color.getBlue());
return hex;
}
我的问题是关于这个 prop 参数的。我们可以将其均匀地应用于alpha,红色,绿色和蓝色吗?在此示例中, prop 是一个百分比,对吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。