I’m trying to capture a screenshot from my application running on Android using the standard code found in some examples:
var width = Screen.width; var height = Screen.height; var tex = new Texture2D(width, height, TextureFormat.RGB24, false); tex.ReadPixels(Rect(0, 0, width, height), 0, 0); tex.Apply(); var bytes = tex.EncodeToPNG(); Destroy(tex); File.WriteAllBytes(Application.persistentDataPath + "/screenshot.png", bytes);
The file is created, but for some reason I cannot preview this file in Android. If I open it it shows as a corrupted file (black). I tried in a Galaxy Tab running android 2.2 and an Asus Transformer running 3.2.
If I preview the image from a computer it works. It seems to be a problem with a CRC calculation or bad length. I’m not sure, but the error is something that apparently in Windows is tolerable enough to show the file. Anybody who can help me with this issue?