- Home /
Question by
Rustam-Ganeyev · Mar 07, 2013 at 09:24 AM ·
texturepacktextures
Save texture after PackTextures operation
Hi all. Assume we create textureAtlas in editor script and applying PackTextures() operation. How to save texture atlas? Problem is after packing textures atlas texture format becomes dxt5 and it throws an exception "Unsupported texture format - needs to be ARGB32, RGBA32, RGB24 or Alpha8" on EncodeToPNG.
var atlasTexture = new Texture2D(maxAtlasSize, maxAtlasSize, TextureFormat.RGB24, false);
textureCoords = atlasTexture.PackTextures(textures, atlasPadding, maxAtlasSize);
atlasTexture.Apply();
Utils.SaveTextureToFile(atlasTexture, path + "/atlasTexture.png");
Here's the code how I save textures in Utils:
public static void SaveTextureToFile(Texture2D texture, string fileName, bool highQuality = true)
{
Debug.Log(texture.format);
byte[] bytes = texture.EncodeToPNG();
if (File.Exists(fileName)) File.Delete(fileName);
File.WriteAllBytes(fileName, bytes);
}
Comment
Best Answer
Answer by Rustam-Ganeyev · Mar 12, 2013 at 01:57 PM
The right way is to set any texture's format to combine to automatictruecolor, and after that to Combine.
but I can't still understand why Unity doesn't provide save format for me, as additional parameter.