Want to add images of different sizes programmatically,Want to display an image of different sizes programmatically
Hi,
I'm currently struggling on something as simple as adding an image programmatically. What I basically want to do is that I want to randomize a picture out of ca 100 and then I want to pop that one in on a certain place in the screen.
My struggles :
I can add the image programmatically but the size is way of and more often than not the image has to squeeze in to a too small space, preserving aspect also means that I get white sides if the image is smaller.
The problem is basically different size pictures that I want to pop up but I have no idea how to make it look decent.
One idea I had would be to create the image component after I have randomized the picture and then I can get the image details and use that to add the image component which I then add the picture too?
Its a bit messy
Any help or unity documentation pointers are wildly appreciated!,Hi,
I would like my code to first randomize among a lot of images (about 100) and then depending on the answer pop that image up on the screen. This means that the images will have different sizes and what would be great is if the image fills fully (so I don't have any white on any side.
My idea is to set ALPHA to fully transparent and then after filling the image I will pop it up to visible but where I get lost is how I get the. image component to adjust to the size of the image. (Currently its way too small and the image squeezes in).
Any Unity documentation regarding it would be great, I'm now thinking that I might need to vector an image component in to the position I want with the size I want of that image and then push it in.
Sorry for the question, probably stupid, one of those where I suddenly just went "what the hell?"
best Martin
Your answer
![](https://koobas.hobune.stream/wayback/20220613032851im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Changing Unity.UI.Panel Color 3 Answers
How to put images in questions of a quiz , where did the database through String [ ] ? 0 Answers
How to make a UI Image appear/disappear? 2 Answers
Creating prefab from image files 3 Answers
One person has reported that the game freezes in a strange way while testing, please help 0 Answers