我需要将一个RenderTexture对象保存为.png文件,然后将该文件用作包裹3D对象的纹理.我的问题是现在我无法使用EncodeToPNG()保存RenderTexture对象,因为RenderTexture不包含该方法.如何将RenderTexture对象转换为Texture2D对象?谢谢!
// Saves texture as PNG file.
using UnityEngine;
using System.Collections;
using System.IO;
public class SaveTexture : MonoBehaviour {
public RenderTexture tex;
// Save Texture as PNG
void SaveTexturePNG()
{
// Encode texture into PNG
byte[] bytes = tex.EncodeToPNG();
Object.Destroy(tex);
// For testing purposes, also write to a file in the project folder
File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png", bytes);
}
}
Run Code Online (Sandbox Code Playgroud)