IEnumerator CaptureScreenshot2(Rect rect)
{
// 先创建一个的空纹理,大小可根据实现需要来设置
Texture2D screenShot = new Texture2D(Screen.width, Screen.height/*, TextureFormat.RGB24, false*/);
canvas.SetActive(false);//屏蔽UI
yield return new WaitForEndOfFrame();
// 读取屏幕像素信息并存储为纹理数据,
screenShot.ReadPixels(rect, 0, 0);
screenShot.Apply();
// 然后将这些纹理数据,成一个png图片文件
byte[] bytes = screenShot.EncodeToPNG();
canvas.SetActive(true);
//-----本地创建图片
string filename = Application.dataPath + "/Screenshot.png";
System.IO.File.WriteAllBytes(filename, bytes);
Debug.Log(string.Format("截屏了一张图片: {0}", filename));
//-----网路创建图片
string tempS = System.Convert.ToBase64String(bytes);
WWWForm form = new WWWForm();
form.AddField("image",tempS);
WWW www = new WWW("http://project.weily.org/uim/index.php", form);
yield return www;
print(www.text);
//-----在NGUI3XX的版本下,将路径复制到剪贴板
TextEditor te = new TextEditor();
te.content = new GUIContent("http://project.weily.org/uim/" + www.text);
te.OnFocus();
te.Copy();
}
笔记笔记~