2014-10-30 103 views
4

我正在创建一个应用程序,我希望能够存储屏幕截图,然后再显示它。我的代码运行良好,屏幕截图存储并看似也没有问题的程序收到。但是,它没有显示屏幕截图,这非常令人沮丧。这是我的代码:截图截图和显示

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); 

     } 

    } 

我希望我提供的信息就足够了。如果不是,请不要犹豫,问。

+1

这可能是一个好主意,还张贴此对http://answers.unity3d.com/ – sydan 2014-10-30 15:18:23

+0

哪里你'screenshot'对象从何而来?它是一个Unity GameObject吗? – 2014-10-31 13:24:00

回答

1

尝试加载图像是这样的:

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

然后,加载图像:

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

这应该工作,我不能对代码进行测试,因为我不已经安装了统一在这台PC上。

取自这里的代码,请不要犹豫问!

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

+0

谢谢。但我已经解决了这个问题。 – 2014-11-11 15:45:31