Get the real texture size?

I have some texture set to nearest power of 2.
So if I have a 910x400, it will be scale to 1024x512.

Aspect ratio was 2.275:1 is now 2:1

It’s possible to get the real size after the import? I want the original aspect ratio.

I can do it with System.Drawing.Bitmap and load the original file but I want to know if it’s possible with only Unity.

It’s possible to turn off automatic scaling of textures with dimensions that aren’t powers of two. I don’t know how Unity handles this under the hood, but I assume it would preserve the actual size of the image (e.g., when querying texture dimensions). Of course, it’s better to use textures with power-of-two dimensions if possible.

To disable scaling, open the texture import settings window, set Texture Type to Advanced and change Non Power of 2 from To nearest to None.

public static void GetTextureRealWidthAndHeight(TextureImporter texImpoter, ref int width, ref int height)
System.Type type = typeof(TextureImporter);
System.Reflection.MethodInfo method = type.GetMethod(“GetWidthAndHeight”, BindingFlags.Instance | BindingFlags.NonPublic);
var args = new object { width, height };
method.Invoke(texImpoter, args);
width = (int)args[0];
height = (int)args[1];