浣跨敤RenderTexture鍜宑amera.targetTexture鐢熸垚蹇収
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浣跨敤RenderTexture鍜宑amera.targetTexture鐢熸垚蹇収相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/targe' title='targe'>targe
texture return 闀滃ご 鍙傛暟 ext game pix 娓叉煋Camera鏈変竴涓猼argetTexture灞炴€э紝鍦ㄨ缃簡targetTexture鍚庯紝Camera浼氬湪娓叉煋鏃跺皢鍏跺睆骞曚笂鐨勫浘鍍忔覆鏌撳埌targetTexture涓婏紝鍙互浣跨敤蹇収瀹炵幇闀滃ご鍒囨崲绛夌壒鏁?/p>
鍏蜂綋瀹炵幇:
private Texture2D CaptureCamera(Camera camera, Rect rect)
{
RenderTexture buffer = RenderTexture.GetTemporary((int)rect.width, (int)rect.height, 1);
camera.targetTexture = buffer;
camera.Render();
// 婵€娲昏繖涓猺t, 骞朵粠涓腑璇诲彇鍍忕礌銆?
RenderTexture.active = buffer;
Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
screenShot.ReadPixels(rect, 0, 0);// 娉細杩欎釜鏃跺€欙紝瀹冩槸浠嶳enderTexture.active涓鍙栧儚绱?
screenShot.Apply();
// 閲嶇疆鐩稿叧鍙傛暟锛屼互浣跨敤 camera 缁х画鍦ㄥ睆骞曚笂鏄剧ず
camera.targetTexture = null;
RenderTexture.active = null;
GameObject.Destroy(buffer);
return screenShot;
}
以上是关于浣跨敤RenderTexture鍜宑amera.targetTexture鐢熸垚蹇収的主要内容,如果未能解决你的问题,请参考以下文章