How to Convert HTML colors to Unity Colors c#

So I’m using Texture2D.GetPixel() in a function called setUpMap (listed below) to parse a .png file and read each pixel, and if the pixel is one color create one type of terrain, or if its another color create another type of terrain, sort of a heightmap. The problem is I want to use a HTML color to compare to the pixel (because that is what gimp uses to choose a color), I have a function called HTMLToColor (listed below) to do that but when I use that function on a HTML color like say, 007f00, it converts it to:

RGBA(0.000, 127.000, 0.000, 1.000)

But GetPixel() sees the pixel as:

RGBA(0.000, 0.498, 0.000, 1.000)

I need a way to convert the color my function returns from a [0,255] to a [0.1] I think.

Thanks I hope I was clear.

This is the function that reads the pixels and creates the terrain:

void setUpMap(string mapName) {
Texture2D tex = Resources.Load(“Level0”) as Texture2D;

    if (tex == null)
    {
        Debug.Log("File Not found: " + mapName);
        return;
    }

    Debug.Log("Loading Level Please Wait...");

	for (int y=0;y<tex.height;y++) {
		for (int x=0;x<tex.width;x++) {
			Color c = tex.GetPixel (x, y);
            GameObject tmp = null;

            Debug.Log("Color: " + c + "

" + “HMTL: " + HMTLToColor(”#007f00", c));

            if ( c == HMTLToColor("#007f00", c) ) // Trees
            {
                tmp = trees;
            }
            if (c == HMTLToColor("#000000", c)) // Grass
            {
                tmp = grass;
            }

            //Debug.Log("R: " + c.r + "G: " + c.g + "B: " + c.b);

            Instantiate(tmp);

            tmp.transform.localScale = new Vector3(2, 2, 2);

            tmp.transform.position = new Vector3(x, y, 10);
        }
	}
}

This is the function that converts the HTML color to unity color:

public static Color HMTLToColor(string hexstring, Color c)
{
if (hexstring.StartsWith(“#”))
{
hexstring = hexstring.Substring(1);
}

    if (hexstring.StartsWith("0x"))
    {
        hexstring = hexstring.Substring(2);
    }

    if (hexstring.Length != 6)
    {
        throw new Exception(string.Format("{0} is not a valid color string.", hexstring));
    }

    byte r = byte.Parse(hexstring.Substring(0, 2), NumberStyles.HexNumber);
    byte g = byte.Parse(hexstring.Substring(2, 2), NumberStyles.HexNumber);
    byte b = byte.Parse(hexstring.Substring(4, 2), NumberStyles.HexNumber);

    return new Color(r, g, b, c.a);
}

If you’re simply looking to change the range of 0-255 to 0-1 you can do the following:

current / max

Where current is the current value between 0-255 and max is the maximum color value which is 255.

Ex. 128/255 = .5

@Knight023

Have you looked at Color32.Color:

and Color32.Color32?