I need to get the average color of a Texture generated at runtime (actually the video background of Vuforia camera). To do that, I converted this Texture to a Texture2D using a script found on this forum:
Texture mainTexture = renderer.material.mainTexture;
Texture2D texture2D = new Texture2D(mainTexture.width, mainTexture.height, TextureFormat.RGBA32, false);
RenderTexture currentRT = RenderTexture.active;
RenderTexture renderTexture = new RenderTexture(mainTexture.width, mainTexture.height, 32);
Graphics.Blit(mainTexture, renderTexture);
RenderTexture.active = renderTexture;
texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
texture2D.Apply();
Color[] pixels = texture2D.GetPixels();
RenderTexture.active = currentRT;
This works fine on editor but when testing it on an android device, GetPixels() only returns a red color value, blue and green ones remain 0. Yet, the texture is clear, the only thing is that it is shown on a redscale.
I thought it could come from an unsupported texture format but I have not been able to find any information about that.
Does anyone know the reason for which it happens?