- Home /
Android returning white in Texture2D.GetPixel(x,y)
I am making a colour picker that only uses gui elements created in code. It uses the mouse/touch position and GetPixel to get the colour of the selected part of the image.
//Vector2 Pos2 = new Vector2(Input.mousePosition.x - Pos.x, -(Screen.height - Input.mousePosition.y - Pos.y - Size.y));
Vector2 Pos2 = new Vector2(Input.GetTouch(0).position.x - Pos.x, -(Screen.height - Input.GetTouch(0).position.y - Pos.y - Size.y));
Pos2.x = Mathf.Clamp(Pos2.x, 0, Size.x-1);
Pos2.y = Mathf.Clamp(Pos2.y, 0, Size.y-1);
CrosshairPos = new Vector2(Pos2.x - 12, Size.x-Pos2.y - 12);
colour = ColourTex2D.GetPixel((int)(Pos2.x/Size.x * ColourTex2D.width), (int)(Pos2.y/Size.y * ColourTex2D.height));
This works on computers when it is built for PC but if it is set to be android, it crashes. When it is built for android, it opens on the android device and shows the correct crosshair position but the colour variable does not change from white. Is GetPixel compatible with android. How can this be fixed?
Answer by samqweqwe · Oct 15, 2014 at 09:28 PM
I found the problem. The textures used were on automatic compression which made them compress in a format that android could not read. changing the compression to RGBA 3bit worked. This can be changed in the texture import setting in default.
Had the same kind of problem. Tried to change compression as suggested, but couldn't find any RGBA 3 bits. I thought you meant 32 bits rather than 3, but it didn't work for me. Tried a few other compressions without any success. I expect to encounter the same problem with iOS build...