forum

Home / DeveloperSection / Forums / How to take a screenshot and save to file as jpg?

How to take a screenshot and save to file as jpg?

Anonymous User 2312 16-Oct-2014
I am trying to Take a screencapture and save it to a file in jpg format.
This is what I have so far:

    string jpgFile = Application.persistentDataPath + "/scrn-1.jpg";
    Texture2D tex = new Texture2D (Screen.width, Screen.height);
    tex.ReadPixels (new Rect(0, 0, Screen.width, Screen.height), 0, 0);
    tex.Apply ();
    var bytes = tex.EncodeToJPG();
    Destroy (tex);
    System.IO.File.WriteAllBytes(jpgFile, bytes);
I have found that running this in Unity on iOS gives me:

JPEG parameter struct mismatch: library thinks size is 372, caller expects 360

However if I change the conversion to tex.EncodeToPNG(); and change the file name to .png everything works fine. I am not sure how to proceed any assistance would be appreciated. Thanks.

c# c#  android 
Updated on 16-Oct-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By