4

I'm creating an application where i want to be able to store a screenshot, and then display it afterwards. My code is running fine, the screenshot is stored and seemingly also received by the program without a problem. However, it is not displaying the screenshot, which is quite frustrating. This is my code:

void OnGUI(){
    if (GUI.Button (new Rect(940,y+25, Screen.width/30, Screen.height/14), Tex7)){
        Debug.Log ("Selfie-maker");

        folderPath = Application.persistentDataPath + "/screenshot.png"; 
        Application.CaptureScreenshot(folderPath);



        Debug.Log ("Screenshot number " + screenshotCount +" taken!");
        screenshotCount ++; 

    }
    if(GUI.Button (new Rect(940,y+65, Screen.width/30, Screen.height/14), Tex)){

        Debug.Log ("Anders");
        fileName = Path.Combine(Application.persistentDataPath, "screenshot.png");
        bytes = File.ReadAllBytes(fileName);
        screenshot = new Texture2D(0,0,TextureFormat.ATF_RGB_DXT1, false);
        screenshot.LoadImage(bytes);

        } 

    }

I hope that the information I have provided will suffice. If not, please don't hesitate to ask.

Steven
  • 166,672
  • 24
  • 332
  • 435

1 Answers1

1

Try to load image like this:

string fullFilename = Path.Combine(Application.persistentDataPath, "screenshot.png");

Then, load the image:

WWW www = new WWW(fullFilename);
Texture2D texTmp = new Texture2D(0,0,TextureFormat.ATF_RGB_DXT1, false);
www.LoadImageIntoTexture(texTmp);

This should work, I can´t test the code because I don´t have Unity installed on this PC.

Code taken from here, don´t hesitate to ask!

http://answers.unity3d.com/questions/25271/how-to-load-images-from-given-folder.html