- Home /
Saving an EncodeToPNG(); to disk at runtime?
So basically I am working on the basics of perlin noise terrain generators in unity. However, I can't seem to figure out how to save the finished PNG file to disk. This isn't about changing an existing image, it is about creating a new image. Here is the affected code so far.
var byt = tex.EncodeToPNG();
System.IO.File.WriteAllBytes("Assets/test.png", byt);
This is in javascript, by the way.
I can't see what could possibly go wrong with this code. I do the very exact same thing in my screenshot-taking script. However I do this in editor-time, not game-time. Have you tried to invoke this code while in the editor rather than when the game runs?
Yeah, it's weird because i actually ended up finding the solution, and I didn't need to change this code at all... I think the problem was somewhere else in the code.
Answer by sendel76 · Sep 12, 2011 at 10:39 PM
in my case it was easy:
had to use
Rect[] uvs = atlasTexture.PackTextures(textureList,0,2048,false);
instead of
Rect[] uvs = atlasTexture.PackTextures(textureList,0,2048,true);