- Home /
setPixel not working with custom Colors
I'm drawing over a texture, but some magic reason when I create a color using new Color() the pixels don't keep the Color I set. Take a look at this fragment of the code :
public static Texture2D BuildTexture (int width, int height, Color colorP)
{
Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
for (int a = 0; a < texture.width; a++) {
for (int b = 0; b < texture.height; b++) {
texture.SetPixel (a, b, colorP);
}
}
return texture;
}
and here the test ...
Color testColor = new Color(152,40,152);
Texture2D test1 = PrimitiveHelper.BuildTexture(10,10,testColor);
test1.SetPixel(0,0,testColor);
Color c1 = test1.GetPixel(0,0);
Debug.LogError("color1=" + testColor + " ctexture=" + c1);
The result is ... color1=RGBA(152.000, 40.000, 152.000, 1.000) ctexture=RGBA(1.000, 1.000, 1.000, 1.000)
any ideas ?
Comment
Best Answer
Answer by athanazio · Oct 26, 2012 at 09:41 AM
after some tests find out that only works IF the color is defined with float values !!!
Color testColor = new Color(0.5,0.1,0.5);
works fine
Color testColor = new Color(152,40,152);
is reset to white in the texture !!!
If you want to use 0-255 values, you need to use Color32
Color32 testColor = new Color(152,40,152);
Otherwise, the color values are set by using 0.0 - 1.0
@clunk47: Can you fix your typo? You still use "new Color"