I am attempting to export textures attached to objects in the Unity Editor as image files, and then later download them from a web server and reattach them to their objects inside a web player. This is an essential component of the Whirld project.
If I gather the texture’s byte array for exporting using EncodeToPNG(), the textures have too large a filesize for my taste - and worse, when I load them in a web player, I cant find any way to re-add their mip maps.
Is it possible for me to export textures in the format that they are optimized to inside Unity’s build pipeline, while preserving their mipmaps and other properties that make them useful? If not, what are my options to overcome this difficulty?
I don’t think you will get anywhere with the .NET image class - it isn’t a part of the Mono library that comes with Unity and you’ll most likely have problems if you try to find it from elsewhere.
PNG usually doesn’t compress anywhere near as well as JPG, so there isn’t much you can do to reduce the file size. If you are just saving the images yourself to a local file, you might be able to use a tool like ImageMagick to convert them from PNG to JPG in bulk (Unity can import JPG over the web, just not export). Otherwise, if you have Unity Pro, you might be able to use an image compression library written in C/C++ to encode your textures.
ImageMagick sounds like a somewhat viable option!
A custom C++ library sounds even better, but I don’t yet have Unity Pro.
While researching how to invoke ImageMagick from Unity, I have found several references to a C# .net wrapper called MagickNet - but it looks like it’s homepage is offline. I’ll post back here once I figure out how to make this work…