插值颜色

时间:2012-11-27 12:48:45

标签: vb.net colors interpolation

您好我在java中有以下代码片段需要转换为vb.net

float position =(value - startValue) / (middleValue - startValue);
Color4f result = new Color4f();
result.interpolate(startColor, middleColor, position);
return result;

有谁知道如何在vb.net中进行color4f.interpolate? 在这里找到了一篇关于使用lambda运算符的c#的文章,但我不知道它们是什么意思以及如何在vb.net中实现它们

Stackoverflow链接到c#文章(Color Interpolation Between 3 Colors in .NET

vb.net中color4f的最佳选择是什么?

感谢。

1 个答案:

答案 0 :(得分:0)

此功能似乎或多或少有效:

Public Function interPolateColor(ByVal firstcolor As Color, ByVal secondcolor As Color, ByVal alpha As Double) As Color
    Dim R As Double = ((1 - alpha) * Convert.ToInt32(firstcolor.R)) + (alpha * Convert.ToInt32(secondcolor.R))
    Dim B As Double = ((1 - alpha) * Convert.ToInt32(firstcolor.B)) + (alpha * Convert.ToInt32(secondcolor.B))
    Dim G As Double = ((1 - alpha) * Convert.ToInt32(firstcolor.G)) + (alpha * Convert.ToInt32(secondcolor.G))
    Dim A As Byte = 255
    Return Color.FromArgb(A, Convert.ToByte(R), Convert.ToByte(G), Convert.ToByte(B))
End Function