- Home /
Question by
Hims · Feb 16, 2015 at 07:40 AM ·
camerawwwscreenshot
how to preview screenshot immediately after its taken ??
i am using following script to preview the screenshot but i am not being able to display the latest screenshot.. plz if any one can correct the script then please help with this.
using UnityEngine;
using System.Collections;
using System.IO;
public class TakeScreenshot : MonoBehaviour
{
public long screenshotCount = 8;
long i = 0;
public int imgcnt = 0;
public bool clicked;
public GUIStyle capSty;
public GameObject myPreviewObject;
//private int currentSlide = 1;
public WWW www;
public string screenshotFilename;
public string screenshotFilename2;
void Awake()
{
//check if directory doesn't exit
if (!System.IO.Directory.Exists("D//SliderImages/Screenshots"))
{
//if it doesn't, create it
System.IO.Directory.CreateDirectory("D://SliderImages/Screenshots");
}
if (!System.IO.Directory.Exists("D//SliderImages/Screenshots/tempApp"))
{
//if it doesn't, create it
System.IO.Directory.CreateDirectory("D://SliderImages/Screenshots/tempApp");
}
// Add file sizes.
DirectoryInfo d = new DirectoryInfo("D://SliderImages/Screenshots");
FileInfo[] fis = d.GetFiles();
foreach (FileInfo fi in fis)
{
if (fi.Extension.Contains("jpg"))
i++;
}
screenshotCount = i;
}
// Check for screenshot key each frame
void Update()
{
// take screenshot on up->down transition of F9 key
if (Input.GetKeyDown("f9"))
{
clicked = true;
do
{
screenshotCount++;
screenshotFilename = "D://SliderImages/Screenshots/" +"screenshot" + screenshotCount + ".jpg";
} while (System.IO.File.Exists(screenshotFilename));
Application.CaptureScreenshot(screenshotFilename);
StartCoroutine ("showImg");
}
}
IEnumerator showImg(){
yield return new WaitForSeconds (1.0f);
DirectoryInfo d = new DirectoryInfo("D://SliderImages/Screenshots/");
FileInfo[] fis = d.GetFiles();
foreach (FileInfo fi in fis)
{
if (fi.Extension.Contains("jpg"))
imgcnt++;
}
print ("IMAGES IN DIRECTORY"+imgcnt);
//yield return new WaitForSeconds (1.0f);
string[] filePaths = Directory.GetFiles ("D://SliderImages/Screenshots/" , "*.jpg");
print (filePaths.Length);
print (filePaths.Length - 1);
www = new WWW ("file://" + filePaths [filePaths.Length-1]);
yield return www;
capSty.normal.background = www.texture;
clicked = true;
yield return new WaitForSeconds (1.0f);
clicked = false;
}
void OnGUI()
{
if (clicked) {
GUI.Button (new Rect (0, 0, 1024, 768), "", capSty);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613183431im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Take screenshot of pixels OUTSIDE the game window? 0 Answers
Open screenshot in file location Android 0 Answers
View Ip cameras remotely over the internet 0 Answers
Create a break screen effect 0 Answers