1.Application.CaptureScreenshot("Screenshot.png", 0);

2.

  1. exture2D CaptureScreenshot2(Rect rect)
  2. {
  3. // 先创建一个的空纹理,大小可根据实现需要来设置
  4. Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24,false);
  5. // 读取屏幕像素信息并存储为纹理数据,
  6. screenShot.ReadPixels(rect, 0, 0);
  7. screenShot.Apply();
  8. // 然后将这些纹理数据,成一个png图片文件
  9. byte[] bytes = screenShot.EncodeToPNG();
  10. string filename = Application.dataPath + "/Screenshot.png";
  11. System.IO.File.WriteAllBytes(filename, bytes);
  12. Debug.Log(string.Format("截屏了一张图片: {0}", filename));
  13. // 最后,我返回这个Texture2d对象,这样我们直接,所这个截图图示在游戏中,当然这个根据自己的需求的。
  14. return screenShot;
  15. }
  16. 截全屏(如下图, 注:有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.

  1. Texture2D CaptureCamera(Camera camera, Rect rect)
  2. {
  3. // 创建一个RenderTexture对象
  4. RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);
  5. // 临时设置相关相机的targetTexture为rt, 并手动渲染相关相机
  6. camera.targetTexture = rt;
  7. camera.Render();
  8. //ps: --- 如果这样加上第二个相机,可以实现只截图某几个指定的相机一起看到的图像。
  9. //ps: camera2.targetTexture = rt;
  10. //ps: camera2.Render();
  11. //ps: -------------------------------------------------------------------
  12. // 激活这个rt, 并从中中读取像素。
  13. RenderTexture.active = rt;
  14. Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24,false);
  15. screenShot.ReadPixels(rect, 0, 0);// 注:这个时候,它是从RenderTexture.active中读取像素
  16. screenShot.Apply();
  17. // 重置相关参数,以使用camera继续在屏幕上显示
  18. camera.targetTexture = null;
  19. //ps: camera2.targetTexture = null;
  20. RenderTexture.active = null; // JC: added to avoid errors
  21. GameObject.Destroy(rt);
  22. // 最后将这些纹理数据,成一个png图片文件
  23. byte[] bytes = screenShot.EncodeToPNG();
  24. string filename = Application.dataPath + "/Screenshot.png";
  25. System.IO.File.WriteAllBytes(filename, bytes);
  26. Debug.Log(string.Format("截屏了一张照片: {0}", filename));
  27. return screenShot;
  28. }

Unity3d之截图的更多相关文章

  1. Unity3d之截图方法

    http://blog.csdn.net/highning0007/article/details/37991787 Unity3d之截图方法 分类: Unity3D2013-11-28 17:13  ...

  2. Unity3D随意截图并保存

    http://blog.csdn.net/awnuxcvbn/article/details/9199245 效果 代码 <pre name="code" class=&qu ...

  3. Unity3D for VR 学习(2): 暴风魔镜框架探索

    学习一个新技术,有三个法宝: 法宝1: 掌握厂家提供的用户API手册 法宝2: 掌握厂家提供的demo样例 法宝3:<每个研发人员都应树立的一个demo模式> 故,学习魔镜4技术,亦如是也 ...

  4. Unity3d截图保存到Android相册的实现

    Unity3d截图保存到Android相册的实现-----------------------------ultrasoon 季风原创--------------------------------- ...

  5. 【Unity3D】Unity3D 摄像机带透明截图

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/CropCamera.html ↓↓↓下面的废话可以不看↓↓↓ 最近处理了一批我的游戏的图标,步骤特别繁琐, 需要先 ...

  6. 在Unity3D中利用 RenderTexture 实现游戏内截图

    using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; publ ...

  7. (转)Unity3d的3种截图方法

    下面是我总结的.在u3d中的,三种截屏方法: 1.使用Application类下的CaptureScreenshot方法. void CaptureScreen() { Application.Cap ...

  8. 获取Unity3D虚拟摄像机的图像

    最新博客地址已转到: http://blog.csdn.net/zzlyw?viewmode=contents   ------------------------------------------ ...

  9. [Unity3D]自己动手重制坦克舰队ArmadaTank

    [Unity3D]自己动手重制坦克舰队ArmadaTank 我玩过一款坦克游戏ArmadaTank(坦克舰队),如下图所示 几个月前我尝试用Unity3D重制这款游戏,已经可以玩起来了.下面是在PC上 ...

随机推荐

  1. 认识position=fixed

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-01-13) position=fixed是相对于浏览器边框的位置.

  2. iOS开发-HTTP请求

    什么是URL?URL就是资源的地址.位置,互联网上的每个资源都有一个唯一的URLURL的基本格式: URL中常见的协议 (1)HTTP 超文本传输协议,访问的是远程的网络资源,格式是http:// h ...

  3. 【剑指offer】顺时针打印矩阵

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/26053049 剑指offer上的第20题,九度OJ上測试通过. 题目描写叙述: 输入一个矩 ...

  4. hdu 3339 In Action 背包+flyod

    In Action Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=333 ...

  5. python中import失败解决的简单办法

    例如:import pkg_resources失败 可以print sys.path查看,从其他机器上cp -r过来即可,如下例子: 从另外一个正常的机器上scp过来/usr/ali/lib/pyth ...

  6. Effective C++ Item 37 绝不又一次定义继承而来的缺省參数值

    本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:绝对不要又一次而来的缺省參数值.由于缺省參数值都是静态绑定,而 virtual 函数 ...

  7. 推荐安卓开发神器(里面有各种UI特效和实例)

    网上有很多开源的安卓类库很好用,对于刚学习安卓的童鞋亦或者老鸟都是很好的学习对象. 我平时有关注开源代码的习惯,这么多年也搜集了不少精彩的源码. 到后来发现自己手机里装的都是几百个demo app,删 ...

  8. Linux中的svn客户端RabbitVCS-2

    我们都知道,自从svn出道以来,很多人都预言,cvs将会被其取代.就如同他们预言maven要取代ant一样.可见,svn的流行.在Windows中,最常用到的开源免费的svn客户端就是Tortoise ...

  9. hdu1050 Moving Tables

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1050 求区间上点的最大重叠次数. #include <stdio.h> #include &l ...

  10. initrd映像文档的作用和制作

    1.http://pan.baidu.com/s/1dDrGeKL 2.http://wenku.baidu.com/link?url=qPa_jfkEZCbERnwMYWLwm9EZJ_ebMRJA ...