Mufan
1
Hi all!
I use trivial mechanic to save texture to png.
Texture2D texture = new Texture2D (width, height, TextureFormat.ARGB32, true);
texture.ReadPixels(new Rect(0, 0, width, height), 0, 0);
texture.Apply();
byte[] bs = texture.EncodeToPNG();
File.WriteAllBytes("foo.png", bs);
Destroy(texture);
But now I want to save compressed PNG. So I added this:
texture.Compress(false);
And it stopped working as expected. Because EncodeToPNG only supports ARGB32 & RGB24.
So, is there any way to save DXT1/DXT5 texture to png? Via EncodeToPNG or smth else?
Thanks!
C2tP
2
I got this to work by first creating a RenderTexture with RenderTexture.GetTemporary() and then using Graphics.Blit(compressed_tex,render_texture);
Now that its in a RenderTexture you can convert to a Texture2D with
RenderTexture.active = render_texture;
Texture2D destination_texture = new Texture2D(width, height);
destination_texture.ReadPixels(new Rect(0, 0, render_texture.width, render_texture.height), 0, 0);
destination_texture.Apply();
Now you have a Texture2D with read flag on so now EncodeToPNG() should work!
obviously its not very fast… I use it as a debug tool to rip out textures from our assetbundles so that we can double check whats inside