2
我需要將RenderTexture對象保存到.png文件,該文件然後將用作包裝3D對象的紋理。我的問題是現在我無法使用EncodeToPNG()保存RenderTexture對象,因爲RenderTexture不包含該方法。我如何將RenderTexture對象轉換爲Texture2D對象?謝謝!將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);
}
}