Resources读取2d纹理 转换为png格式

文档

  1. ImageConversion.EncodeToPNG

操作步骤

  1. 图片开启 Read/Write Enable
  2. 使用Texture2D的EncodeToPNG方法将纹理转换为字节数组
  3. 使用文件流,存储图片到其他位置
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();
}

猜你喜欢

转载自blog.csdn.net/weixin_43796392/article/details/125547659
今日推荐