Saving Screenshot and using it as texture at runtime

Hello,

I need a bit of help in this.
In one single action I try to:
-Save a screenshot of my scene from my main camera view. (No problem for that)
-Create a quad. (No problem for that)
-Apply the screenshot as texture onto that quad(This I don’t manage and I can’t figure out why).

When I run preview the code below returns “Unable to load Texture…”
Some advice anyone?

	function Update () 
	{
		if (Input.GetKeyDown ("space"))
		{
	 	Application.CaptureScreenshot("Assets/Resources/UnityScreenshot.png");
		print ("space key was pressed");
		var photoFrame : GameObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
		photoFrame.renderer.material = new Material (Shader.Find(" Diffuse"));
		photoFrame.renderer.material.SetColor ("_Color", Color.red);
		var photo : Texture2D =  Resources.Load("UnityScreenshot.png", Texture2D);
		if(photo)
	      	{
	        Debug.Log("Texture Loaded Sucessfully...");
	        photoFrame.renderer.material.mainTexture = photo;
	     	}
	    	else
	     	{
			Debug.Log("Unable to Load texture...");
			}

		}
	}

As siegeon mentioned check whether you have UnityScreenshot.png in resource folder or not,
and saving image on Resources, is not a good idea because in unity you can do that but when it comes to devices i don’t think you will work as it will not give acess to resource
Folder ,So use Persistent data path

Example

IEnumerator save_png_player()
	{
		if (Application.platform == RuntimePlatform.Android)
		{ 
        	File.WriteAllBytes( Application.persistentDataPath+"/"  +name+".jpg",bytes );
		}
		else
		{
			File.WriteAllBytes( Application.dataPath+"/Resources/save_screen/"+name+".jpg",bytes );
		}
	 
 
		yield return null;


	}

For Loading png from location and use it in rin time

void Start()
	{

        
     if (Application.platform == RuntimePlatform.Android)
		{ 
 
			_FileLocation=Application.persistentDataPath; 
		}
		else
		{
		_FileLocation = Application.dataPath+"/save_screen";
		}
		
	} 


Void loadjpg()
{

String url = @"file://"+_FileLocation+"/"+filename+".jpg";

 photoFrame.renderer.material.mainTexture = url ;
}

You cannot save and use the screenshot in the same frame, this is due to the fact that the screenshot is taken after rendering so after all updates and so on.

I would recommend to save in the persistent data path then access the data turn them into texture and use it:

private Texture2D texture = null;

IEnumerator SaveAndUse()
{
   // Take shot
   Application.CaptureScreeshot(url);
   // Wait
   yield return null;
   // Find and use
   byte[] file = File.ReadAllBytes(url);
   texture = new Texture2D(4,4);
   texture.LoadImage(file);
}

I guess that should do it since it did for me.

File extensions must be omitted for Resources.Load. Try just

var photo : Texture2D = Resources.Load("UnityScreenshot", Texture2D);