I assume you mean changing individual pixels? In this case, use the GetData() and SetData() Texture2D class.
For example, you can get an array containing the colors of individual pixels by doing the following:
Note that you can use other GetData() overloads to select only the section.
So, to replace each pixel of a specified color with a different color:
// Assume you have a Texture2D called texture, Colors called colorFrom, colorTo Color[] data = new Color[texture.Width * texture.Height]; texutre.GetData(data); for(int i = 0; i < data.Length; i++) if(data[i] == colorFrom) data[i] = colorTo; texture.SetData(data);
To see if the shades are similar, try this method:
private bool IsSimilar(Color original, Color test, int redDelta, int blueDelta, int greenDelta) { return Math.Abs(original.R - test.R) < redDelta && Math.Abs(original.G - test.G) < greenDelta && Math.Abs(original.B - test.B) < blueDelta; }
where * delta is the tolerance for each color channel you want to accept.
To answer your edit, there is no built-in function, but you can just use the mixture of ideas from the two sections above:
Color[] data = new Color[texture.Width * texture.Height]; texutre.GetData(data); for(int i = 0; i < data.Length; i++) if(IsSimilar(data[i], colorFrom, range, range, range)) data[i] = colorTo; texture.SetData(data);
Callum rogers
source share