Take the 2-minute tour ×

Hi I have the following snippet in java I need to convert to vb.net

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

Does anyone know how I can do the color4f.interpolate in vb.net? Have found an article here for c# which use lambda operators but I have no idea what they mean and how to implement them in vb.net

Stackoverflow link to c# article (Color Interpolation Between 3 Colors in .NET)

And what is the best alternative for color4f in vb.net?


share|improve this question
Not sure why you would need lambda for that, sounds like very basic math: How do I interpolate colors with this: c = (1 - t) * c0 + t * c1 –  Neolisk Nov 27 '12 at 16:20
add comment

1 Answer

up vote 0 down vote accepted

This function seems to work more or less:

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
share|improve this answer
add comment

Your Answer


