- Home /
Question by
tMs · Jan 09, 2013 at 12:21 PM ·
texture2dscreenshotreadpixels
Texture2D readPixels: How to only read a section of the camera view?
Hi,
i am trying to get only a section of the camera view when i take a screenshot using readPixels. How can i do that? I have tried to change the rect left and top parameters but when i set them higher than 0 then i receive a grey texture.
Here is the part of the code
RenderTexture renderTexture = new RenderTexture(screenshotWidth, screenshotHeight, 32);
screenshotCamera.targetTexture = renderTexture;
screenshot = new Texture2D(screenshotWidth,screenshotHeight, TextureFormat.ARGB32, false);
screenshotCamera.clearFlags = CameraClearFlags.Color;
screenshotCamera.Render();
screenshotCamera.clearFlags = CameraClearFlags.Nothing;
RenderTexture.active = renderTexture;
screenshot.ReadPixels(new Rect(0, 0, screenshotWidth, screenshotHeight), 0, 0);
RenderTexture.active = null;
Destroy(renderTexture);
The screenshotCamera is a extra camera, i can´t use the main camera because i screenshot some elements on another layer.
Thanks for helping.
Comment
Your answer
Follow this Question
Related Questions
Texture.Apply() Crashes at Resolutions under 1920x1080 1 Answer
Using Screenshot as Texture 4 Answers
What's wrong with my screenshot function? 1 Answer
How to get banner ad's screenshot to a texture? 0 Answers
Using Texture2D.GetPixels() to take a screenshot and then show it on an Image - iOS problems. 1 Answer