0

There is any way with code to export a .png or .tga file to local disk in Unity? I need to write a converter that loads asset bundles and converts them to the original source image files. I need to create those files, in a way that anyone could open them with Photoshop, for instance. Any idea about how to do it?

Thanks. David

DavidGuaita
  • 501
  • 1
  • 7
  • 18
  • Are you looking for a unity editor script or is it for a standalone app? And why do you need to do this, what kind of app is this going to be? – CodeSmile Jul 28 '14 at 08:20
  • I think an Unity Editor Script is more suitable. Basically is for an existing game that needs the textures to be modified, and due to production issues now is easier to export the images from the asset bundles of the game. – DavidGuaita Jul 28 '14 at 09:17
  • So I assume you're already able to extract the textures from the asset bundles? If so, all that remains is a call to EncodeToPNG. http://docs.unity3d.com/ScriptReference/Texture2D.EncodeToPNG.html Afaik there is no equivalent for TGA, so you'd have to write that yourself based on the data in a Texture2D. – Bart Jul 28 '14 at 10:32

2 Answers2

2
void Save(Texture2D texture)
{
    var bytes = texture.EncodeToPNG();
    File.WriteAllBytes(EditorUtility.SaveFilePanel("Save PNG", Application.dataPath + "/../", "Font", "png"), bytes);
}
Rakka Rage
  • 15,941
  • 8
  • 33
  • 45
-2

You can save image in TGA format using Encode To TGA plugin: http://u3d.as/rWt

Bart
  • 1