|
IEnumerator Capture(){ yield return new WaitForEndOfFrame(); int width = Screen.width; int height = Screen.height; Texture2D texture = new Texture2D(width,height,TextureFormat.RGB24,false); Rect rect = new Rect(0, 0, width, height); tex.ReadPixels(rect, 0, 0); #if UNITY_ANDROID texture.Apply();//不压缩 #elif UNITY_IPHONE TextureScalePoint.ScalePoint (texture, width * 0.5, height * 0.5); //压缩 #endif byte[] image = texture.EncodeToPNG(); File.WriteAllBytes(Application.persistentDataPath + "/" + "capture.png",image);//存储png图} |
|