【发布时间】:2017-05-30 14:03:37
【问题描述】:
我需要将 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);
}
}
【问题讨论】: