c# - 屏幕截图捕获和显示

标签 c# unity3d texture2d

我正在创建一个应用程序,我希望能够在其中存储屏幕截图,然后在之后显示它。我的代码运行良好,屏幕截图已存储并且似乎也被程序毫无问题地接收到。但是,它没有显示屏幕截图,这非常令人沮丧。这是我的代码:

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

关于c# - 屏幕截图捕获和显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26656784/

相关文章:

c# - 类值 C# Unity 中的奇怪而奇怪的案例

c# - 如何使用 NetworkManager 为所有客户端同步场景加载

c# - unity给出 "Type or namespace definition, or end-of-file expected"错误

javascript - 将 blob 文件发送到服务器

c# - 同时播放 2 个声音

c# - Entity Framework 4.0 批量操作的性能

ffmpeg - rgb32 数据资源映射。使用directx memcpy

ios - 如何防止 ios 平台上 unity 图像质量下降

c# - 使用 Monogame/XNA 将 Sprite 绘制到永久的 Texture2d

c# - ObservableCollection 即使在 .NET 4.5 中也不是线程安全的?