툴/유니티

[C#] 유니티 렌더텍스쳐 이미지로 저장

스튜디오 오버그래픽스 2021. 8. 2. 03:22

유니티에서 렌더텍스쳐 이미지로 저장

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

public class Shutter : MonoBehaviour
{
	 public RenderTexture DrawTexture;   //PNG저장할 타겟 렌더 텍스쳐
     
     void RenderTextureSave()
     {
     	RenderTexture.active = DrawTexture;
        var texture2D = new Texture2D(DrawTexture.width, DrawTexture.height);
        texture2D.ReadPixels(new Rect(0, 0, DrawTexture.width, DrawTexture.height), 0, 0);
        texture2D.Apply();
        var data = texture2D.EncodeToPNG();
        File.WriteAllBytes("C:/Example/Image.png", data);
     }


}