- Home /
texture.width not returning actual image pixels
This one is simply confusing. I have an image with the dimensions of 480 x 73.
When I call (texUI : Texture) var sizeX : float = texUI.width; var sizeY : float = texUI.height;
it returns 512 x 64. ??
The inspector import settings for the texture are (and I should mention I don't have much idea what any of this does!) :
Texture Type : Texture
Alpha from Grayscale : Unchecked
Wrap Mode : Clamp
Filter Mode : Bilinear
Aniso Level : 1
Max Size : 512
Format : Truecolor
Unity converts all imported textures to power of two for mip-mapping.
@$$anonymous$$$$anonymous$$ay you might have to reimport your texture. The non-power of two option is defined while importing in the advanced texture type.
No worries , I just found it while searching after the first answer (before your comment, but thanks). Changing "Texture Type : Advanced" has given me a more comprehensive menu. Thanks =]
Answer by Eric5h5 · Jun 03, 2012 at 06:11 PM
You didn't say what the most important setting is in this case, namely "non power of two". Which is the answer.
No worries , I just found it while searching after this answer. Changing "Texture Type : Advanced" has given me a more comprehensive menu. Thanks.
For future readers : http://unity3d.com/support/documentation/$$anonymous$$anual/Textures.html#texturesizes
and : http://unity3d.com/support/documentation/$$anonymous$$anual/Textures.html
Answer by ModelOX · Nov 24, 2021 at 04:52 PM
If anyone else stumbles upon this in the future the issue is, as eric tried to point out 9 years ago, that texture.width/height returns the width/height of the texture after unity converts it to a power of 2. So if you're working with the pixel values of the texture it won't return the values your expecting. If you're still looking for an answer to this might I direct you towards https://forum.unity.com/threads/getting-original-size-of-texture-asset-in-pixels.165295/
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
change child texture problem 2 Answers
How to switch the texture being used by the material of the mesh renderer 1 Answer
How could I make the texture on one object follow the rotation of another object? 0 Answers
Having wrong texture on my model? 1 Answer