Determine Textures Image Type (JPG, PNG, etc.)

Is it possible to determine a Texture or Texture2D image type? Ie, is it JPG, PNG, GIF, BMP?

I am aware there is the property Texture2D.format but this gives me RGB24. The reason why I need to know if because I need to convert the image to a Byte array so I can store the image in a SQLite3 database.

public byte[] toByteArray(Texture t) {

    Image img = somehow convert a texture to a Image //Image.FromFile(@"C:\Lenna.jpg");
    byte[] arr;
    using (MemoryStream ms = new MemoryStream())
    {
      img.Save(ms, t.type); //System.Drawing.Imaging.ImageFormat.Jpeg);
      arr =  ms.ToArray();
    }
    return arr;
}

http://docs.unity3d.com/Documentation/ScriptReference/Texture2D-format.html http://docs.unity3d.com/Documentation/ScriptReference/TextureFormat.html no PNG option or such just raw data

SOLVED! Looks like problem was with calling PlayGamesPlatform.Activate(); AFTER logging in. That line must be before logging in.

1 Answer

1

Source image formats aren’t used in Unity, and a Texture type can’t contain that information since it’s no longer relevant after the image is imported; at that point it’s RGB24, DXT1, etc. depending on what your import settings were.

Ah nice, good catch. I didn't include code for login to keep it small.