Users Pricing

forum

Home Forums How to take a screenshot and save to file as jpg? – MindStick

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

Anonymous User 2757 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.

1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md