Log in or register to post comments

Can't read pixel values from VideoBackgroundTexture on Android build

May 2, 2018 - 4:42am #1

Good day.

We're trying to get the RGB values of the Vuforia background image, took by the camera.

We get the background image by doing this:

Texture renderText;
renderText = VuforiaRenderer.Instance.VideoBackgroundTexture;
Texture2D Text2D = renderText as Texture2D;

or this:

GameObject Go = GameObject.Find("BackgroundPlane");
MeshRenderer MR = Go.GetComponent<MeshRenderer>();
Texture2D Text2D = MR.materials[0].mainTexture as Texture2D;

After this, we can assign this Texture 2D as the texture of a UI Raw Image and it works properly on every platform.

When we try to read its pixel values

Color32[] cols = Text2D.GetPixels32();
string n = "";
for (int i = 0; i < 5; i++)
n += cols[i]; print(n);

the Unity Editor will successfully return the color of the given pixel - for example "RGBA(110, 130, 143, 225)".

However, an Android build will always return "RBA(0, 0, 0, 0)".

Do you know a way around this problem?

Thank you.

Can't read pixel values from VideoBackgroundTexture on Android build

May 14, 2018 - 6:42am #3

This should be doable and seems like a Unity issue. I'm guessing it has something to do with compression format on the original render texture.  Android probably can't read directly off of some formats.  I'd create a texture 2d and specify the format and give it the data instead of casting the render texture.  



RenderTexture.active = myRenderTexture;

myTexture2D.ReadPixels(new Rect(0, 0, myRenderTexture.width, myRenderTexture.height), 0, 0);

myTexture2D.Apply();

 

Can't read pixel values from VideoBackgroundTexture on Android build

May 14, 2018 - 3:35am #2

Anyone?

Log in or register to post comments