纳金网

标题: 截图保存的代码 [打印本页]

作者: 狂风大尉    时间: 2014-6-30 16:10
标题: 截图保存的代码
  1. private var fileName : String = "screenShot";
  2. function writeFile()
  3. {
  4.     var tex : Texture2D= new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24, false);
  5.     tex.ReadPixels(Rect(0,0,Screen.width,Screen.height),0,0);
  6.     tex.Apply();
  7.     var bytes : byte[]=tex.EncodeToPNG();
  8.     Destroy(tex);
  9.     var thisName : String = fileName+".png";
  10.      var cachedAssetBundle =Application.dataPath+"/Resources/"+thisName;
  11.     var cache = new System.IO.FileStream(cachedAssetBundle, System.IO.FileMode.Create);
  12.     cache.Write(bytes,0,bytes.Length);
  13.     cache.Close();
  14.     Debug.Log("Cache saved: "+cachedAssetBundle);
  15.    
  16. }
复制代码

作者: 毛毛虫    时间: 2014-6-30 16:23

谢谢分享,很不错啊
作者: wucnj    时间: 2014-7-1 10:15
感谢分享!!!
作者: wa5145416    时间: 2014-8-15 18:08
挺厉害的。。




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5