您的位置:首页 > 大数据 > 人工智能

WaitForEndOfFrame

2017-08-08 18:54 375 查看
using System.IO;
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
// Take a shot immediately
IEnumerator Start()
{
UploadPNG();
}

IEnumerator UploadPNG()
{
// We should only read the screen buffer after rendering is complete
yield return new WaitForEndOfFrame();

// Create a texture the size of the screen, RGB24 format
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);

// Read screen contents into the texture
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();

// Encode texture into PNG
byte[] bytes = tex.EncodeToPNG();
Destroy(tex);

// For testing purposes, also write to a file in the project folder
// File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png", bytes);

// Create a Web Form
WWWForm form = new WWWForm();
form.AddField("frameCount", Time.frameCount.ToString());
form.AddBinaryData("fileUpload", bytes);

// Upload to a cgi script
WWW w = new WWW("http://localhost/cgi-bin/env.cgi?post", form);
yield return w;
if (w.error != null)
print(w.error);
else
print("Finished Uploading Screenshot");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐