I wanted to add a screenshot taker in my unity project, but what surprised me was when I compiled it and ran it, there was nothing new in my data folder. I used 3 diffrent methods to try and save a screenshot, but nothing worked.
I get lag every time it takes I press the screenshot button, but there is no file at all. Is it just me or is it a known problem or something? I run windows 7, and I specifically made the code try to save to < data_folder >/Screenshot.png. Heres the code:
function Update () {
//if user presses PrintScreen take a screenshot
if(Input.GetKeyDown(KeyCode.Print)) {
PRINTSCREEN();
}
else if (Input.GetKeyDown(KeyCode.Escape)) {
Application.Quit();
}
}
function PRINTSCREEN() {
yield WaitForEndOfFrame();
var SCREENSHOT = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
SCREENSHOT.ReadPixels(Rect(0,0,Screen.width, Screen.height),0,0);
SCREENSHOT.Apply();
var SCRN = SCREENSHOT.EncodeToPNG();
Destroy(SCREENSHOT);
//Doesn't work
//Application.CaptureScreenshot(Application.dataPath + "/Screenshot.png");
//Also doesn't work
//var ENCSCRN:System.IO.BinaryWriter = new System.IO.BinaryWriter(System.IO.File.Open(Application.dataPath + "/Screenshot.png", System.IO.FileMode.Create));
//ENCSCRN.Write(SCRN);
//ENCSCRN.Close();
//Also doesn't work
System.IO.File.WriteAllBytes(Application.dataPath + "/Screenshots.png",SCRN);
}
DaveA
2
You could always rely on good ole Prt Sc button copying to clipboard? or Alt Prt Sc to grab just the window. Do you need this for yourself or the end user, and is it essential for the end user to have this screenshot in that file?
CgShady
4
I have the same issue.
KeyCode.Print simply won’t work.
You can try with the following…
function OnGUI () {
if (Input.GetKey (KeyCode.Print)) {
GUI.Label(Rect(Screen.width/2-100,Screen.height/2-50,200,100), "Print Screen Key Down");
}
}
system
3
You can modify this, here is a simple Javascript I conjured up to save a screenshot each time you hit “p” key. It has an append filename var so you can take as many shots as you want, and it will name them by adding +1 at the end of each file.
var ext : String = “.png”;
var append : int = 0;
var filename : String = “Screenshot”;
function Update()
{
if(Input.GetKeyDown(“p”))
{
append+=1;
Application.CaptureScreenshot(filename + num + ext);
}
}