unity3d 截屏
2013-01-21 14:36
411 查看
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);//设置Texture2D tex.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指定相机截屏并存储在手机相册中(安卓)
- Unity3d之如何截屏
- unity3d 自带截屏
- Unity3D 游戏引擎之IOS截屏 话筒录音 录制截屏视频保存沙盒(另类实现方法 )
- Unity3D的截屏函数
- [Unity3D]Unity3D游戏开发之截屏保存精彩瞬间
- Unity3D -- 自定义范围截屏
- Unity3d ios/android 截屏到默认目录
- Unity3d 截屏并上传到服务器
- Unity3D 截屏功能
- unity3d更换材质 及截屏
- Unity3D研究院之IOS截屏 话筒录音 录制截屏视频保存沙盒
- Unity3d 截屏
- Unity3d中的三种截屏方式
- Unity3d 截屏
- [转载]Unity3d三种截屏方法
- Unity3d 截屏之后转换成Texture2d
- unity3d 截屏
- unity3d中用ReadRixels实现截屏
- unity3D调用外接摄像头,保存图片、不使用截屏方式