Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ScreenShot : MonoBehaviour {
- public Camera camera;
- public int resWidth = 2550;
- public int resHeight = 3300;
- private string screensPath;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- }
- public void TakeHiResShot()
- {
- if (screensPath == null)
- {
- #if UNITY_ANDROID && !UNITY_EDITOR
- screensPath = "/sdcard/DCIM/RegionCapture";
- #elif UNITY_IPHONE && !UNITY_EDITOR
- screensPath = Application.persistentDataPath;
- #else
- screensPath = Application.dataPath + "/Screens";
- #endif
- System.IO.Directory.CreateDirectory(screensPath);
- }
- 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 = screensPath + "/screen_" + System.DateTime.Now.ToString("dd_MM_HH_mm_ss") + ".png";
- System.IO.File.WriteAllBytes(fileName, bytes);
- Debug.Log(string.Format("Took screenshot to: {0}", fileName));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement