Hello,
I have a little performance problem with Application.CaptureScreenshot function.
It’s 2D scrolling game for IOS. When the player dies, I capture screen by CaptureScreenshot. But it drops half of the FPS and lags. (from 60 to (30~45)).
Without capturing screenshot, FPS doesn’t drop and the game hasn’t got any lag.
I have tried to reduce hitches by lerping timescale to 0.5. It improves little bit but not quite enough.
Does anyone know best way to take a screenshot?
Thanks in advance.
Thank you @Neurological for keep helping me. I have solved this question by RenderTexture as you adviced.
-
Assets → Create → Render Texture
-
public RenderTexture currentRT; // Drag here created texture.
-
Called when the player dies:
private IEnumerator TakeScreenshot() {
yield return new WaitForEndOfFrame();
Camera.main.targetTexture = currentRT;
yield return new WaitForSeconds(0.2f);
Camera.main.targetTexture = null;
}
- When screenshot needed, save to Document
void save () {
int width = 512;
int height = 256;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
// Read screen contents into the texture
RenderTexture.active = ScreenShot.Instance.currentRT;
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] screenshot = tex.EncodeToPNG();
RenderTexture.active = null;
File.WriteAllBytes(pathToImage, screenshot);
}