trying to convert rgb from a .net Color to a string such as “red” or “blue”

If you have a list of known colors with names, you can see which of those known colors a given target color is ‘closest’ to, using a ‘closeness’ function along the lines of (F# code):

let Diff (c1:Color) (c2:Color) =
    let dr = (c1.R - c2.R) |> int
    let dg = (c1.G - c2.G) |> int
    let db = (c1.B - c2.B) |> int
    dr*dr + dg*dg + db*db

Whichever one of the known colors has the smallest diff to the target color you want to name, use that name.

Leave a Comment