Unity3D 把Texture2D保存到文件
原链接:https://answers.unity.com/questions/245600/saving-a-png-image-to-hdd-in-standalone-build.html
保存Texture2D到文件,可以是exr,jpg,png格式:
import System.IO;
function SaveTextureToFile( texture: Texture2D,fileName)
{
var bytes=texture.EncodeToPNG();
var file = new File.Open(Application.dataPath + "/"+fileName,FileMode.Create);
var binary= new BinaryWriter(file);
binary.Write(bytes);
file.Close();
}
调用方式:
SaveTextureToFile( myTexture,"picture.png");
NOTE:Texture源必须是可读的。如果是你自己创建的,则没问题。如果是你导入的,则需要把它改成可读。
另附上API截图: