屏幕截图和显示

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
你的screenshot对象来自哪里?它是Unity的GameObject吗? - Ludovic Feltz
1个回答

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

这应该可以工作,我无法测试代码,因为此电脑上没有安装Unity。
代码取自此处,不要犹豫,随时提问!

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接