Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RyanAchtenSoma · Sep 10, 2015 at 03:34 AM · runtimeui imagelayout

Scale UI Image source image

Hi Unity Community

I have a UI Image whose Source Image is assigned at runtime. These images will be of various sizes and I need them to be scaled to fit the bounds of the layout element so that the entire image is visible.

I have tried a number of approaches for this, however I can’t seem to get this to work; could anyone please provide me some pointers on how to achieve this?

Many thanks in advance, Ryan

Current Code:

 public function ContextImgImp(){
 
     Debug.Log("Context Img Located at: " + texLocation);
         
     var wwwDirectory = "file://" + texLocation; //this will probably need to change for other OS (PC = file:/ [I think?]) - **REVISE**
     Debug.Log("Tex located at: " + wwwDirectory);
         
     newImgTex = new Texture2D(512, 512, TextureFormat.DXT1, false);
     
     while(true){
     
         var www : WWW = new WWW(wwwDirectory);
         
         yield www;
     
         Debug.Log("Done Downloading Texture");
         www.LoadImageIntoTexture(newImgTex);
         
         if (www.isDone){
             break; //if done downloading image break loop
         }
     }    
     
     var imgSprite = contImg.sprite;
     var imgRect = imgSprite.rect;
     var imgPivot = imgRectTrans.pivot;
     var pixelScale = 100;
     Debug.Log("Pixel Scale:" + pixelScale);
     
     newImgSprite = Sprite.Create(newImgTex, imgRect, imgPivot, pixelScale);
     contImg.sprite = newImgSprite;
 
     //imgRectTrans.rect.size = Vector2(130,130);
     //contImg.sprite.rect.size = Vector2(130,130);
     //contImg.type = Image.Type.Simple;
 }

Current image display: alt text

Whole image to be displayed: alt text

screen-shot-2015-09-10-at-30951-pm.png (20.7 kB)
uv-check-512px.jpg (220.9 kB)
Comment
Add comment · Show 2
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 RyanAchtenSoma · Sep 10, 2015 at 03:41 AM 0
Share

Forgot to mention that the layout is controlled via Layout Groups, which conflicts for control over the rect with other potentially useful Layout Compoonents such as Aspect Ratio Fitter and Content Size Fitter etc

alt text

screen-shot-2015-09-10-at-33800-pm.png (20.4 kB)
avatar image RyanAchtenSoma · Sep 17, 2015 at 02:22 AM 0
Share

One potential approach to resolving this I considered was creating a smaller thumbnail image in the import. I did a bunch of trials with various source image sizes and this certainly changed the way the image is being cropped. However trails at the rect size (130px) were not possible due to the $$anonymous$$imum size for the source img being 132px. The 132px size (included in image) still incurred cropping.

Can anyone provide me any pointers as to how this issue can be resolved? Getting no responses on this.

source img size tests

screen-shot-2015-09-16-at-83015-pm.png (56.8 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by itsharshdeep · Sep 17, 2015 at 06:23 AM

alt text

Can Layout element allowing you to make the anchor like same as I posted the screenshot, If yes then pls check with the same. May be it work


stretch-anchor.png (40.1 kB)
Comment
Add comment · Show 2 · 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 RyanAchtenSoma · Sep 17, 2015 at 07:29 AM 0
Share

Hi itsharshdeep, thanks for your response

I tried this out, doesn’t affect anything. I’m pretty sure this is overridden by the parent layout group components.

Expanding the rect size to account for the size of the image isn’t really what I’m after; I’m ai$$anonymous$$g to scale the image to fit the rect size, not vice versa.

avatar image itsharshdeep RyanAchtenSoma · Sep 18, 2015 at 04:43 AM 0
Share

Ok :)

Sorry I dont have any idea about this. Lets hope that Some more knowledgeable person will come and respond on this

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

29 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Resizing UI Image but with minimum width 2 Answers

Change UI shader property at runtime 1 Answer

Add Image dynamically in runtime 2 Answers

Display loaded UI Image in Container with native size 0 Answers

MessageBox Panel (How to add resizable Text container?) 0 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