Unity display image at specific size - image

We are working on a mobile application that requires a user to position a printed image on top of the touchscreen of his mobile device. The application should display a placeholder where the image has to be placed, with the correct size of the physical image, so we know exactly where it is in order to interact with it.
This works great on devices of which we know the exact screensize, but we want this to work on all mobile devices. Our developer who is working on this project appears to have problems to get the required information to do the calculations.
We are using Unity and it has to work on both iOS and Android. Can anyone give us some pointers on how to tackle this problem please?

Get the aspect ratio of the image by dividing the width by height.
Set a placeholder in the location it should be and give it a fixed constant height OR width.
If the height is fixed, multiply height by the aspect float to get the new width. If the width is fixed, divide the width by the aspect to get the new height.

Related

Xamarin - How to create a layout that will adjust its size across all devices while maintaining its ratio

I am essentially creating a trading card that must maintain a 2.5x3.5 ratio.
I created the cards background image (with logo's and things that will never change)
I need to create a layout/frame/whatever that will maintain a 2.5x3.5 ratio so I can give it this background image (or image aspectfit) that will never stretch, given that the layouts aspect ratio should never change. This way no matter the size of a phones screen, the height and width size will adjust to fit in any size screen, but the view's aspect will always remain in tact...
The idea is, I will then place labels into this card through Xamarin forms using an API. Name, image, details, etc...
The image of the cards logos will never change, hence the background image, but the labels will change according to character...
Any ideas?

How determine the size of the image to use for apps?

I am using the flutter to develop the app, and in the app, I want to use the image.
Since the image can increase the size of the app if not properly sized and it can also destroy the app if the image doesn't look good.
I am not worried about the resolution because I will aim for the highest display dpi and generate for all the lower screen, but the problem is in deciding the image size
I could have a large image or small image with the same dpi. In flutter number is used to size the element in the screen and this number could mean different pixel length for different device and it doesn't give the size of the card in the app, hence could not decide the image size.
How to determine the size of the image to use for the given element in App?
I will know the width and height of the item where I want to use my image in number (not in pixel length or any physical unit) but how do I decide the size of the image which would look good on all the devices?
For deciding the size , you can size acc to the width and height of screen and this can be achieved using MediaQuery class.
For Example :
double width = MediaQuery.of(context).size.width*0.1 //for 10 % width
double height = MediaQuery.of(context).size.height*0.1 //for 10 % width
And If we talk about the resolution than, for resolution add the same image or asset in asset file as well as in 2x folder and 3x folder in the asset folder itself.
Flutter framework picks the correct sized asset according to the resolution.
For your reference see the Official Documentation.

Xcode auto alignment and constraints - equal distances between several images

I have nine images ad I want them to display in a single column on the device. The images should retain their original height and width (that I will set) and the only thing that should change according to the screen height should be the distance between the images.
I'm not really sure how to approach this problem - I tried using a container, but it didn't turn out as I expected. Should I set the constraints programmatically? And if so, how? What should the constraints be if I want the images to be from top to bottom of he screen?
Consider using a stack view:
On iOS, UIStackView provides UIStackViewDistributionEqualSpacing, which I believe will arrange images as you want
On Mac, NSStackView can automatically space images as you describe if the individual image views are all in the same gravity and retain their sizes at a high enough priority (using constraints or content hugging priority)

Image resize when running the app on my device (Android Studio)

I'm just starting with Android Studio and I have an old device running Android Froyo (API 8) with 240x320px display resolution.
I have an image with 240px width and when I use an ImageView with wrap_content to display that image on my device, it doesn't use the whole width of my device screen.
When I set the ImageView width to 240px, It occupies the whole width of my device (so I know my device has actually 240px width), but I can see it's blurred out.
Apparently the image is being resized to a lower resolution before being compiled and loaded to run on my device.
If anyone can help me explaining why this happens, I would really appreciate, because I couldn't find out, searching here and on Google.
.
Thanks!
As I didn't get an answer to my question, thinking overnight, I believe I figured it out.
My display has 2.8", so I thought it's density would be around 143dpi ( SQRT(240^2+320^2)/2.8 ).
With that density, objects declared in 'dp' would take too much space on the screen.
So, after comparing the 'dp' value with the actual number of pixels on my screen, I found out its density is actually 120dpi (LDPI), so a 160dp object actually doesn't have one inch on my screen, but 3/4 of an inch.
Maybe this is done by the device, not the compiler (I don't know), but everything I declare in 'px', is multiplied by 3/4 before loading due to its density.
I hope I'm right and that I have helped anyone with the same doubt.

XCode - when it comes to UiWebView there is an issue

I'm totally new when it comes to xcode, but there occured a problem:
I'm designing an iPad-App(Retina Display) in html/css with the standard retina resolution of 2048x1536px...the problem is, that when I open the app on the pad, the page turns out to be way too huge. If I'm reading out the UiWebView-Resolution I get 1024x768...am I able to change this to get the real iPad dimension?
thx for your help!
Best regards,
daft
Dimension values on iOS are described in points. Each point can have different number of pixels - depends on screen's pixel density. UIWebView interprets html document size value as point - so 1 html pixel means 1 point.
I suggest you two options to cope with that:
1. Design you're web app to resolution 1024x768 and insert images which are scaled to 50% size to have more pixel density.
2. Leave page in 2048x1536 resolution and use UIWebView api to scale content.

Resources