- Home /
RenderTexture and Readpixels android problem.
This is where I stuck. Basicly i trying to make "ShareMyScore-Image", an image with current score, when player loose.
While everything works just fine in editor, on android device i got black screen.
What am I doing wrong?
SecondCamera.aspect = 1.0f;
Texture2D virtualPhoto = new Texture2D(1024, 1024, TextureFormat.RGB24,false);
SecondCamera.enabled = true;
RenderTexture.active = ScreenShot; //public link RenderTexture
SecondCamera.Render();
virtualPhoto.ReadPixels(new Rect(0, 0, virtualPhoto.width, virtualPhoto.height), 0, 0,false);
virtualPhoto.Apply();
SecondCamera.enabled = false;
File.WriteAllBytes(Application.persistentDataPath + "/1.png", virtualPhoto.EncodeToPNG());
$$anonymous$$e too: RenderTexture.Create failed: format unsupported - 2.
error at: mTexShadow2D.ReadPixels(mRectCopy, 1, 1);
Unity 2017.3.1f Only occur with my Android tablet, on my android phone it runs Ok.
Have you made any progress on this problem? I suspect it's related to texture formats being overridden to different types for different platforms.
Answer by WARdd · Jan 03, 2020 at 02:58 PM
I was dealing with the same problem. It seemed to get fixed by making sure there is always something rendering to the rendertexture e.g. a small image, or for a more clean solution, a solid black background.
I'm not sure why this made a difference, maybe the texture gets internally disabled on some platforms if it's fully transparent when Unity boots up?
Would appreciate if someone can figure out more about this, but I'll post this solution in case it can help someone.
Answer by RobAnthem · Feb 21, 2018 at 09:07 AM
Umm, you are literally just creating a blank 1024x1024 image, reading the blank pixels, applying the still blank pixels, and then serializing it. Nowhere are you assigning pixels to the virtualPhoto, or assigning it as a render texture. It will always be a black image.
ReadPixels has a slightly deceptive name, it takes the active screen texture and applies it to a texture. The ScreenShot rendertexture is presumably being rendered to and then applied to virtualPhoto using ReadPixels
Your answer
Follow this Question
Related Questions
RenderTexture.Create failed: format unsupported 0 Answers
Object shown on top of another, rendering priorities? 2 Answers
Best way to access RenderTexture immediately after camera render 0 Answers
Trying to reset image settings on main camera smoothly 1 Answer
ClearFlags don't seem to work when I manually call Render() on my cameras. 0 Answers