文档
操作步骤
- 图片开启 Read/Write Enable
- 使用Texture2D的EncodeToPNG方法将纹理转换为字节数组
- 使用文件流,存储图片到其他位置
string path = Application.streamingAssetsPath + "/NewFolder";//设置存储路径
Texture2D tx = Resources.Load<Texture2D>("girl");//加载图片
if (tx)
{
byte[] bytes;
bytes = tx.EncodeToPNG();//转换为PNG
FileStream stream = new FileStream(path + "/test.png", FileMode.OpenOrCreate);
stream.Write(bytes, 0, bytes.Length);
stream.Close();
}