Unity三种截图方法
来源:互联网 发布:淘宝怎么判定是否盗图 编辑:程序博客网 时间:2024/06/18 00:15
引用出处:
[1]http://blog.csdn.net/highning0007/article/details/37991787 Unity3d之截图方法
/* *方法一,截取某一帧的整个游戏画面 *a.不能针对某一个相机(camera)的画面,进行截图。 *b.局部画面截图不方便,效率也低,不建议在项目中使用 */ Application.CaptureScreenshot("screenShot.jpg", 0); //方法二,全屏截图 //Rect:截图的区域,左下角为o点 //截全屏: CaptureScreenshot2( new Rect( Screen.width*0f, Screen.height*0f, Screen.width*1f, Screen.height*1f)); //截中间,1/4: CaptureScreenshot2( new Rect( Screen.width*0.25f, Screen.height*0.25f, Screen.width*0.5f, Screen.height*0.5f)); Texture2D CaptureScreenshot2(Rect rect) { // 先创建一个的空纹理,大小可根据实现需要来设置 Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24,false); // 读取屏幕像素信息并存储为纹理数据, screenShot.ReadPixels(rect, 0, 0,false); screenShot.Apply(); // 将这些纹理数据组成一个png/JPG图片文件 //byte[] bytes = screenShot.EncodeToJPG(); byte[] bytes = screenShot.EncodeToPNG(); //string filename = Application.dataPath + "/Screenshot.jpg"; System.IO.File.WriteAllBytes(filename, bytes); Debug.Log(string.Format("截屏: " + filename)); //返回Texture2d对象,可以用直接赋值给Texture2d类型的变量,方便且节省资源 return screenShot; } //方法三:截取某个相机渲染的画面 Texture2D CaptureCamera() { //创建一个RenderTexture对象 RenderTexture texture = new RenderTexture(Screen.width, Screen.height, 0); //临时设置相关相机的targetTexture为RenderTexture的对象,并手动渲染相关相机 renderCamera.targetTexture = texture; renderCamera.Render(); //激活RenderTexture对象,并从中读取像素 RenderTexture.active = texture; screenShot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); screenShot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); screenShot.Apply(); //重置相关参数,以camera能继续在屏幕上显示 renderCamera.targetTexture = null; RenderTexture.active = null; Destroy(texture); //将这些纹理数据转换为byte byte[] bytes = screenShot.EncodeToJPG(); //将纹理数据组成JPG图片文件 string fileName = Application.dataPath + "/Screenshot.jpg"; return screenShot; }
0 0
- Unity三种截图方法
- Unity三种截图方法
- [Unity基础]三种截图方法
- Unity截图的三种方式
- 三种图片截图方法
- Android获取屏幕截图的三种方法
- unity 截图
- Unity截图
- unity的三种物体移动方法
- Unity摄像机的使用三:游戏的截图
- Unity游戏开发中屏幕截图的方法
- Unity三屏全屏方法
- unity中消息传递的三种方法
- 截图的几种方法
- Unity 屏幕截图
- Unity相机截图
- Unity高像素截图
- unity之屏幕截图
- 数据结构之哈希表二(用开散列法实现哈希表)
- 时间戳转换成日期
- 十. Scala函数详解
- Java异常处理
- Yii2 回到顶部插件
- Unity三种截图方法
- Java+Jquery实现转盘抽奖系统
- [IMWeb训练营作业]基于vue仿照今日头条文章详情页面
- hybrid之ionic常见问题
- LearnOpenGL学习笔记9:材质
- 日志规范
- leetcode题解-64. Minimum Path Sum
- 前端面试题总结
- 51nod 2级算法题-1092