Color a greyscale images using a gradient

I’m working on a script that randomally generates a greyscale image. What i want is something similar to what is found on this page http://libnoise.sourceforge.net/tutorials/tutorial3.html ,in the middle of the page. So i want to somehow apply a premade gradient to each color value in each pixel. I have my gradient set up as a Texture2D.

I hope you understand what i’m trying to do.

What would be the best way to achieve this?

You would have to have a gradient 1 pixel wide and 256 pixel’s tall.

get both textures into a color array:

read each pixel in your height map and replace it with a pixel that many bytes into the second array.

for(var i=0; i<heightmapColors.Length; i++){
heightmapColors[i]=gradientColors[heightmapColors[i].r];
}

Apply it back to teh texture:

and appy your changes

Just in case you need more info.

Thanks, this was exactly what i was looking for. I will give it a try

I’m a bit stuck now, i have done what you put in the code window, and i’ve tried applying and saving but all i get is a blank texture.
Can you give me some directions on how the whole apply thing would work?

I don’t know if this is the problem, but Unity wont let me create a texture 1pixel wide (or tall) it gets resized to 256x2. I guess that is because of the “Non Power of 2” which is greyed out for me.

Solved to with help from UnityAnswers, for those interested i’ve posted my functioning script there:
HERE