2014-10-30 55 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