I have tried each of variants: http://wiki.unity3d.com/index.php/ScreenCapture Afterall, simple Application.Capturescreenshot(...) is the least laggy.
Please, tell me, How I can take screenshots without ANY lags? Lots of games on Android has thiis feature, so it's not impossible.
The cause of lag while taking picture is when you try to perform all steps at the same time without waiting after each step. To fix this, you perform one action and wait for many frames then perform the next action then wait again. And if you decide to save the picture during game-play, use Thread to save the picture.
EncodeToPNG()
is another problem but I will talk about another solution for it later on.The code below is good if you want to take screen shot then display it right away while game is running. It will take picture right way then take about 1.5 seconds to save the file.
If you want to take the picture and you are not required to display the image right away, you can save the picture as raw
Texture2D
, then when you want to access/load/display the picture later on, you can read it from file then convert it to PNG later on. The reason for this is thatEncodeToPNG()
is very expensive so if you don't need the picture right away, there is no need to convert it to png. You can do that only when you actually need it as png. So now we can just save it as ".t2D" then load it after and convert the loaded image to ".png".Save as Texture2D ".t2D"
Then when you actually need the image, load Texture2D ".t2D" and then covert it to ".png" followed by deleting the old ".t2D".
Application.CaptureScreenshot()
is slow in general, a faster way is to use aTexture2D
and read all the pixels on the screen on it usingReadPixels()
function than you can encode and save the texture to the hard drive.This is an example of this method:
For a full reference you can use Unity scripting reference page here.