将目标纹理保存为图像

Saving Target Texture as an image

我有一个四边形,它通过 Unity 编辑器设置了目标纹理。我想将四边形上的输出可视化保存为图像。有什么方法可以将它保存为四边形吗?我已经尝试通过 texture2d 但它只是一个正在保存的黑色图像。

试试这个

private void SaveImage(Texture t, string path)
{
    RenderTexture rt = new RenderTexture(t.width, t.height, 0);
    Graphics.Blit(t, rt);
    Texture2D t2d = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
    t2d.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
    File.WriteAllBytes(path, t2d.EncodeToPNG());
}

用法

SaveImage(yourQuad.GetComponent<MeshRenderer>().material.mainTexture, "yourSavePath.png");