Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DarkPixel · Feb 04, 2015 at 04:20 PM · editortextureimport

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TheCatProblem · Feb 04, 2015 at 06:48 PM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DarkPixel · Feb 04, 2015 at 06:58 PM 0
Share

I want to keep the scaling, but I want to adjust the aspect ratio correctly whe I use the texture

avatar image TheCatProblem · Feb 04, 2015 at 07:26 PM 0
Share

As far as I know there isn't an "official" way to retrieve the size before scaling. However, you might try the approach discussed in this forum thread: Getting original size of texture asset in pixels.

avatar image DarkPixel · Feb 05, 2015 at 12:56 PM 0
Share

I prefer to use System.Drawing.Bitmap without using reflection with the importer. In both cases we need to store that information somewhere and use it later. Thanks anyways!

avatar image
0

Answer by icelanguage · Sep 16, 2019 at 04:45 AM

   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];
         }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Editor class "Texture Importer" question (applying settings to multiple texture assets). 2 Answers

Importing FBX with textures 1 Answer

How to stop gradient banding? 2 Answers

How to change the default import settings for textures 1 Answer

All textures constantly changes "Texture Type" to "Advanced" leaving weird light issues 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges