I'm trying to save a list of Texture2D's that are created at runtime.
I am doing something wrong. I'm getting grey textures out at the other end. I initially thought it was ES3 but it's not. Sorry!
This is some test code that does the same thing.
Edit: Ok I am running into GPU/CPU memory issues I guess. Is there any way to get around this to save generated Texture2D's into an es3 file at runtime.
Edit2: This helped me fix the issue. https://docs.unity3d.com/ScriptReferenc ... ctive.html
Code: Select all
public class SaveImages : MonoBehaviour
{
public RenderTexture TestTexture;
public Texture2D texture2D;
private string es3FilePath = "C:/Users/darre/OneDrive/Desktop/MapTest/";
private string es3Filename = "MapTest";
private string biomImageName = "BiomImageName";
private string fileSufix = ".jpg";
// Start is called before the first frame update
void Start()
{
//Create BiomMattes Texture2Ds
for (int i = 0; i < 2; i++)
{
texture2D = new Texture2D(1024, 1024,TextureFormat.ARGB32,false);
Graphics.CopyTexture(TestTexture,texture2D);
ES3.SaveImage(texture2D, es3FilePath + "/" + es3Filename +"/"+ es3Filename + "_" + biomImageName + "_" + i + fileSufix);
SaveTexture(texture2D, es3FilePath + "/" + es3Filename +"/"+ "NotES3_"+es3Filename + "_" + biomImageName + "_" + i + fileSufix);
}
}
//Some other image saving code I hacked together, this works fine.
public void SaveTexture (Texture2D texture, string pathAndFileName)
{
byte[] bytes = texture.EncodeToPNG();
System.IO.File.WriteAllBytes(pathAndFileName, bytes);
}
}