相机不要UI截图

单独相机 B 渲染UI,单独相机 A 渲染某物。假设我们不要UI,只要那个“”某物“”,截屏的时候用一个RenderTexture接受相机B所见的东西。记得用相机手动渲染一次。记得要使创建的FGO可读。然后用Texture2d从已经可读的TextureRenderTexture中接收,图像(个人对 RenderTexture.active = rt 理解,我还是读不懂大神的,也不知道对不对。大神连接:)。然后编码成二进制。File类写入文件

 

记得善后,清除不需要的RenderTexture和Texture2d

 

另ClearFlag:每次清除。。至于时间间隔是多少?空包没渲染的部分。会每秒秦楚ClearFlag指定的,保证屏幕中所见的是最新的画面。

相机的depth的话。

using System.Collections;

using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class CaptureNoUI : MonoBehaviour {


    string destination = "";
    string picName = "";
    public  Camera noUICamera;






    private void Start()
    {
        destination = Application.dataPath + "/pic/NoUI";
        
    }
    public void Cap()
    {//第三哥参数不知道是什么。不懂。0也行。3(当前相机深度)也行
       RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 3);


        noUICamera.targetTexture = rt;


       noUICamera.Render();//必要的一步。如果不手动render。渲染出来的东西黑色的,虽然这个相机的clearFlag是skyBox


        Texture2D tt = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);


         RenderTexture.active = rt;//把该FGO设置为可读


        // 没有上面这句的时候报错 ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.


        tt.ReadPixels(new Rect (0,0,Screen.width,Screen.height),0,0);


         tt.Apply();//但是这一步写不写都可以有结果出来。


        byte[] b = tt.EncodeToPNG();


        string path = Application.dataPath+"/pic/NoUI/"+Time.time+".PNG";


        File.WriteAllBytes(path,b);
    }


   
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值