码迷,mamicode.com
首页 > 编程语言 > 详细

Unity截图的三种方式

时间:2015-06-04 22:52:25      阅读:601      评论:0      收藏:0      [点我收藏+]

标签:unity   截图   

1.最常见的一种方式

IEnumerator CaputreScreen()
{
    yield return new WaitForEndOfFrame();
    texture.ReadPixels(new Rect(0, 0, width, height), 0, 0);
    texture.Apply();
}

该方法可以截取一个矩形框内的图像,缺点是需要等待一帧结束才可以读取到图像数据

2.Unity自带截图

Application.CaptureScreenshot("Screenshot.png");

这种方式会截取整个屏幕的图像,是最简单的一种方式

3.使用RenderTexture

renderCamera.targetTexture = renderTexture;
renderCamera.Render();

RenderTexture.active = renderTexture;
photoTexture.ReadPixels(new Rect(0, 0, width, height), 0, 0);
photoTexture.Apply();

RenderTexture.active = null;
renderCamera.targetTexture = null;

该方法需要绑定一个Camera来作为渲染Camera,该方法只会得到该摄像机中的图像

Unity截图的三种方式

标签:unity   截图   

原文地址:http://blog.csdn.net/congcongjoy/article/details/46365535

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!