Unity3d之截图
1.Application.CaptureScreenshot("Screenshot.png", 0);
2.
- exture2D CaptureScreenshot2(Rect rect)
- {
- // 先创建一个的空纹理,大小可根据实现需要来设置
- Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24,false);
- // 读取屏幕像素信息并存储为纹理数据,
- screenShot.ReadPixels(rect, 0, 0);
- screenShot.Apply();
- // 然后将这些纹理数据,成一个png图片文件
- byte[] bytes = screenShot.EncodeToPNG();
- string filename = Application.dataPath + "/Screenshot.png";
- System.IO.File.WriteAllBytes(filename, bytes);
- Debug.Log(string.Format("截屏了一张图片: {0}", filename));
- // 最后,我返回这个Texture2d对象,这样我们直接,所这个截图图示在游戏中,当然这个根据自己的需求的。
- return screenShot;
- }
- 截全屏(如下图, 注:有ui):
CaptureScreenshot2( new Rect( Screen.width*0f, Screen.height*0f, Screen.width*1f, Screen.height*1f));
截中间4分之(如下图):
CaptureScreenshot2( new Rect( Screen.width*0.25f, Screen.height*0.25f, Screen.width*0.5f, Screen.height*0.5f));
3.
- Texture2D CaptureCamera(Camera camera, Rect rect)
- {
- // 创建一个RenderTexture对象
- RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);
- // 临时设置相关相机的targetTexture为rt, 并手动渲染相关相机
- camera.targetTexture = rt;
- camera.Render();
- //ps: --- 如果这样加上第二个相机,可以实现只截图某几个指定的相机一起看到的图像。
- //ps: camera2.targetTexture = rt;
- //ps: camera2.Render();
- //ps: -------------------------------------------------------------------
- // 激活这个rt, 并从中中读取像素。
- RenderTexture.active = rt;
- Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24,false);
- screenShot.ReadPixels(rect, 0, 0);// 注:这个时候,它是从RenderTexture.active中读取像素
- screenShot.Apply();
- // 重置相关参数,以使用camera继续在屏幕上显示
- camera.targetTexture = null;
- //ps: camera2.targetTexture = null;
- RenderTexture.active = null; // JC: added to avoid errors
- GameObject.Destroy(rt);
- // 最后将这些纹理数据,成一个png图片文件
- byte[] bytes = screenShot.EncodeToPNG();
- string filename = Application.dataPath + "/Screenshot.png";
- System.IO.File.WriteAllBytes(filename, bytes);
- Debug.Log(string.Format("截屏了一张照片: {0}", filename));
- return screenShot;
- }
Unity3d之截图的更多相关文章
- Unity3d之截图方法
http://blog.csdn.net/highning0007/article/details/37991787 Unity3d之截图方法 分类: Unity3D2013-11-28 17:13 ...
- Unity3D随意截图并保存
http://blog.csdn.net/awnuxcvbn/article/details/9199245 效果 代码 <pre name="code" class=&qu ...
- Unity3D for VR 学习(2): 暴风魔镜框架探索
学习一个新技术,有三个法宝: 法宝1: 掌握厂家提供的用户API手册 法宝2: 掌握厂家提供的demo样例 法宝3:<每个研发人员都应树立的一个demo模式> 故,学习魔镜4技术,亦如是也 ...
- Unity3d截图保存到Android相册的实现
Unity3d截图保存到Android相册的实现-----------------------------ultrasoon 季风原创--------------------------------- ...
- 【Unity3D】Unity3D 摄像机带透明截图
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/CropCamera.html ↓↓↓下面的废话可以不看↓↓↓ 最近处理了一批我的游戏的图标,步骤特别繁琐, 需要先 ...
- 在Unity3D中利用 RenderTexture 实现游戏内截图
using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; publ ...
- (转)Unity3d的3种截图方法
下面是我总结的.在u3d中的,三种截屏方法: 1.使用Application类下的CaptureScreenshot方法. void CaptureScreen() { Application.Cap ...
- 获取Unity3D虚拟摄像机的图像
最新博客地址已转到: http://blog.csdn.net/zzlyw?viewmode=contents ------------------------------------------ ...
- [Unity3D]自己动手重制坦克舰队ArmadaTank
[Unity3D]自己动手重制坦克舰队ArmadaTank 我玩过一款坦克游戏ArmadaTank(坦克舰队),如下图所示 几个月前我尝试用Unity3D重制这款游戏,已经可以玩起来了.下面是在PC上 ...
随机推荐
- 认识position=fixed
(从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-01-13) position=fixed是相对于浏览器边框的位置.
- iOS开发-HTTP请求
什么是URL?URL就是资源的地址.位置,互联网上的每个资源都有一个唯一的URLURL的基本格式: URL中常见的协议 (1)HTTP 超文本传输协议,访问的是远程的网络资源,格式是http:// h ...
- 【剑指offer】顺时针打印矩阵
转载请注明出处:http://blog.csdn.net/ns_code/article/details/26053049 剑指offer上的第20题,九度OJ上測试通过. 题目描写叙述: 输入一个矩 ...
- hdu 3339 In Action 背包+flyod
In Action Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=333 ...
- python中import失败解决的简单办法
例如:import pkg_resources失败 可以print sys.path查看,从其他机器上cp -r过来即可,如下例子: 从另外一个正常的机器上scp过来/usr/ali/lib/pyth ...
- Effective C++ Item 37 绝不又一次定义继承而来的缺省參数值
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:绝对不要又一次而来的缺省參数值.由于缺省參数值都是静态绑定,而 virtual 函数 ...
- 推荐安卓开发神器(里面有各种UI特效和实例)
网上有很多开源的安卓类库很好用,对于刚学习安卓的童鞋亦或者老鸟都是很好的学习对象. 我平时有关注开源代码的习惯,这么多年也搜集了不少精彩的源码. 到后来发现自己手机里装的都是几百个demo app,删 ...
- Linux中的svn客户端RabbitVCS-2
我们都知道,自从svn出道以来,很多人都预言,cvs将会被其取代.就如同他们预言maven要取代ant一样.可见,svn的流行.在Windows中,最常用到的开源免费的svn客户端就是Tortoise ...
- hdu1050 Moving Tables
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1050 求区间上点的最大重叠次数. #include <stdio.h> #include &l ...
- initrd映像文档的作用和制作
1.http://pan.baidu.com/s/1dDrGeKL 2.http://wenku.baidu.com/link?url=qPa_jfkEZCbERnwMYWLwm9EZJ_ebMRJA ...