unity3d 截屏
2024-08-22 14:01:01
原地址: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);//设置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-,Screen.height*0.5-,,),"screen")){
Application.CaptureScreenshot("Screenshot.png");
}
}
这张Screenshot.png图片被存在了当前工程的子目录下了。
最新文章
- <;转>; jsp:include 乱码问题解决
- 解析Javascript中大括号&ldquo;{}&rdquo;的多义性
- WriteFile实现下载
- Eclipse 文本显示行号
- TweenMax动画库学习(三)
- 利用动软代码生成器 自动生成LINQ需要用的数据实体类 (转)
- c、c++混编实现查询本地IP地址
- 【线段树】BAPC2014 E Excellent Engineers (Codeforces GYM 100526)
- .parents() 与 .parent()对比
- USACO Section 1.1-2 Greedy Gift Givers
- 3_Longest Substring Without Repeating Characters -- LeetCode
- sololearn的c++学习记录_4m11d
- 菜鸟脱壳之脱壳的基础知识(五)——利用内存断点寻找OEP
- 通过linux核映射驱动访问GPIO
- ubuntu ssh前后台切换命令相关
- 国内阿里云Maven镜像(速度飞起)
- appscan 9.0.3.10 版本下载
- 把XML保存为ANSI编码
- C语言字节对齐问题详解(对齐、字节序、网络序等)
- ASP.Net Core MVC 网站在Windows服务器跑不起来
热门文章
- 2016 版 Laravel 系列入门教程(五)【最适合中国人的 Laravel 教程】
- VS2013打开项目提示此版本的应用程序不支持其项目类型(.csproj)
- Erlang之父的学习历史及学习建议
- Robot Framework测试框架学习笔记
- (转)eclipse项目导入到android studio中
- Using a Comparison Function for the Key Type
- HackerRank and MiniMax
- Maven学习笔记-03-Eclipse下maven项目在Tomcat7和Jetty6中部署调试
- Python初学笔记
- Color Space