Partial Snapshot of Game Screen
Hello all! I have a snapshot taking class that I am using to take a thumbnail of something on screen. Previously this code worked fine and was taking a full-screen screenshot then cropping it to just what I needed. Now, however, the process appears to take the full screen and stretching it into the size that I'm providing for the partial shot. Below is the code in its current form. private void OnPostRender() { if(takeScreenshotOnNextFrame) { takeScreenshotOnNextFrame = false;
RenderTexture renderTexture = camera.targetTexture;
Texture2D renderResult = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGBA32, false);
Rect rect = new Rect(0, 0, renderTexture.width, renderTexture.height);
renderResult.ReadPixels(rect, 0, 0);
imageArr = renderResult.EncodeToPNG();
RenderTexture.ReleaseTemporary(renderTexture);
camera.targetTexture = null;
}
}
private void TakeScreenshot(int width, int height)
{
camera.targetTexture = RenderTexture.GetTemporary(width, height, 16);
takeScreenshotOnNextFrame = true;
}
public static async Task<byte[]> TakeScreenshot_Static(int width, int height)
{
instance.TakeScreenshot(width, height);
while (imageArr == null)
await Task.Yield();
return imageArr;
}
And the call I'm making for it is: byte[] imageArr = await ScreenshotHandler.TakeScreenshot_Static(810, 810);
Since nothing, as far as I can remember, changed in the code.. I'm thinking this maybe an environment change that I missed. Hopefully someone has run into this issue before.
Thank you!
Your answer
![](https://koobas.hobune.stream/wayback/20220613054247im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
When raycasting, script doesn't detect anything coming into ray yet I did everything right! 1 Answer
I am trying to offset camera x distance from player all the time. Even if the player moves. 1 Answer
I am trying to offset the camera from the player at all times even if the player moves. 0 Answers
List give a count of zero when it have 1 element 1 Answer
What can I do to get Unity to understand the Debug.Drawline command? 1 Answer