---
title: "How to take a screenshot and save to file as jpg?"  
description: "How to take a screenshot and save to file as jpg?"  
author: "Anonymous User"  
published: 2014-10-16  
updated: 2014-10-16  
canonical: https://www.mindstick.com/forum/2397/how-to-take-a-screenshot-and-save-to-file-as-jpg  
category: "c#"  
tags: ["c#", "android"]  
reading_time: 3 minutes  

---

# How to take a screenshot and save to file as jpg?

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) 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](https://answers.mindstick.com/qa/42001/did-adams-follow-washington-s-advice-of-unity-at-home-neutrality-abroad-why-or-why-not) on iOS gives me:\
JPEG [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) [struct](https://www.mindstick.com/blog/83/struct-in-c-sharp-dot-net) mismatch: [library](https://www.mindstick.com/forum/34615/software-framework-vs-library) thinks size is 372, caller expects 360\
However if I change the [conversion](https://www.mindstick.com/forum/1734/conversion-from-32-bit-integer-to-4-chars) to tex.EncodeToPNG(); and change the [file name](https://www.mindstick.com/interview/2597/can-you-have-two-files-with-the-same-file-name-in-gac) to .png everything [works fine](https://answers.mindstick.com/qa/115732/my-software-works-fine-on-windows-10-but-crashes-on-windows-11-why). I am not sure how to proceed any assistance would be appreciated. Thanks.

## Replies

### Reply by marcel ethan

I found this, which lets you save it as .jpg. I normally just use capture screen and save as .png.

Here you go:

```
using UnityEngine;using System.Collections;public class HiResScreenShots : MonoBehaviour {    public int resWidth = 2550;     public int resHeight = 3300;    private bool takeHiResShot = false;    public static string ScreenShotName(int width, int height) {        return string.Format("{0}/screenshots/screen_{1}x{2}_{3}.png",                              Application.dataPath,                              width, height,                              System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));    }    public void TakeHiResShot() {        takeHiResShot = true;    }    void LateUpdate() {        takeHiResShot |= Input.GetKeyDown("k");        if (takeHiResShot) {            RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);            camera.targetTexture = rt;            Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);            camera.Render();            RenderTexture.active = rt;            screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);            camera.targetTexture = null;            RenderTexture.active = null; // JC: added to avoid errors            Destroy(rt);            byte[] bytes = screenShot.EncodeToPNG();            string filename = ScreenShotName(resWidth, resHeight);            System.IO.File.WriteAllBytes(filename, bytes);            Debug.Log(string.Format("Took screenshot to: {0}", filename));            takeHiResShot = false;        }    }}
```

If you just want any kind of picture I highly recommend this:

```
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour {    void OnMouseDown()     {        Application.CaptureScreenshot("Screenshot.png");    }}
```


---

Original Source: https://www.mindstick.com/forum/2397/how-to-take-a-screenshot-and-save-to-file-as-jpg

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
