屏幕截图捕获和显示
本文关键字:显示 屏幕截图 | 更新日期: 2023-09-27 18:28:38
我正在创建一个应用程序,希望能够在其中存储屏幕截图,然后显示它。我的代码运行良好,屏幕截图已存储,程序似乎也收到了,没有任何问题。然而,它没有显示屏幕截图,这很令人沮丧。这是我的代码:
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);
}
}
我希望我所提供的信息将足够。如果没有,请毫不犹豫地询问。
尝试像这样加载图像:
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