unity3d 截屏
生活随笔
收集整理的這篇文章主要介紹了
unity3d 截屏
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原地址:http://www.cnblogs.com/88999660/archive/2013/01/21/2869747.html
void OnGUI(){if(GUI.Button(new Rect(10,70,50,50),"ScreenShot")){StartCoroutine(ScreenShot()); //協程調用} }IEnumerator ScreenShot(){int width = Screen.width;int height = Screen.height;yield return new WaitForEndOfFrame(); //去掉協程試試看會發生什么。Texture2D tex = new Texture2D(width,height,TextureFormat.RGB24,false);//設置Texture2Dtex.ReadPixels(new Rect(0,0,width,height),0,0);//獲取Pixels tex.Apply();//應用改變byte[] bytes = tex.EncodeToPNG();//轉換為byte[]Destroy(tex);Stream flstr = new FileStream(@"d:\1.png", FileMode.Create);//文件操作BinaryWriter sw = new BinaryWriter(flstr, Encoding.Unicode); sw.Write(bytes);sw.Close();flstr.Close(); }另一種方法:
using UnityEngine; using System.Collections;public class example : MonoBehaviour { void OnMouseDown() { Application.CaptureScreenshot("Screenshot.png"); } }function OnGUI(){if(GUI.Button(Rect(Screen.width*0.5-50,Screen.height*0.5-50,100,100),"screen")){Application.CaptureScreenshot("Screenshot.png");}}這張Screenshot.png圖片被存在了當前工程的子目錄下了。
總結
以上是生活随笔為你收集整理的unity3d 截屏的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: emacs vim IDE
- 下一篇: unicode编码问题