I am able to get the actual image height from here
However, I am looking for a way to get the actual height of the image that has been scaled on different device screens.
You can use MediaQuery.of(context).devicePixelRatio combined with the size in DP of your image container.
Related
First of all, sry for my English mistakes, I'm not a native English speaker.
I'm trying to make an UI which is composed of a canvas within different gameObject, and I would like that my canvas scales to the dimension of the screen but keeps its original resolution (16x9 portrait). If it is displayed on a tablet resolution (4x3) then an image is displayed in the space that is not covered by the canvas.
But actually all I've got is a canvas which scales to every resolution, and it changes the aspect of its child (for example a square becomes a rectangle).
Thank you for showing interest in my query!
UI's are heavy beasts. Canvas in Unity have a component attached to themm called Canvas Scaler which is set by default on Constant Pixel Size. You may try to set this property on Scale With Screen Size and then specify the base resolution you want to work with (usually 1920x1080 is a console standart). This is your first step
Then, to avoid strange Image scaling, you may check the property Preserve Aspect, this way the ration of the Sprite into your Image will remain the same indepently of the ratio of the Image
Last, you may play a bit with anchors but this is another story, you should let those at plain center at the beginning and come back to it when you will feel ready
Hope that helped ;)
Your canvas should have a component called Canvas Scaler. Here it should say Constant Pixel Size, change this to Scale With Screen Size and it should lock the Canvas to be the same width / height as the screen. If you want to lock an image to a specific width/height ratio, go to the Image component on the image and check the Preserve Aspect checkbox. This way if you have a 100x100 image, the images width will always be the same as the height. If you have a 200x100 image, the images width will always be twice the height, etc etc etc.
I have the listview with each row have an image on left side and text on right side. I have the xml as shown in below.
<ImageView
android:id="#+id/ivMenuListImage"
android:layout_width="70dip"
android:layout_height="70dip"
android:layout_alignParentLeft="true"
android:scaleType="fitXY"
android:paddingLeft="2dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"/>
I have given the Height and Width as 70x70 and the Images are in higher pixels than this. The list view is displaying well. Now i dont want to use hardcode value. So i gave width and height as wrapcontent and resized the images as 70x70. But the images are looking very blured and image quality is very poor. Please help me.
If your image does not have higher resolution you may need to set
android:scaleType="centerInside"
in order not to stretch the image.
Update:
If you wish the row to appear "larger" on higher dpi devices, first you 1) set all your views' layout_height to wrap_content 2)Create png images with fixed width/height pixels for different density drawable folders. For example, in drawable-mdpi all your png images should have fixed height 70 pixel, then all the rows will appear to be 70dp high in mdpi devices. If you create images of height 96 pixel in hdpi folder, then all hdpi devices will look wider with 96dp height.
I'm trying to to resize my image (from URL) to full screen in my iPhone. However, the size 320x480 which is supposed to be full size is not full screen.
-(IBAction)changeFullSize{
urlImage.contentMode = UIViewContentModeScaleAspectFit;
urlImage.frame = CGRectMake(0,0,320,480);
}
I'm using a UIButton here, so when the user clicks on the opaque button, it changes to a full sized image.
However, there is an empty space between the tab bar at the top and the start of the picture.
What is the correct size for full screen? Is there a way for it to automatically resize to full screen without me specifying the width and height?
Thanks.
You could try and get it from self.view.frame.size but for the entire screen you can use [[UIScreen mainScreen] bounds]. Hope this helps.
you cant just resize your image by changing its frame, since you are using aspect fit, the image will keep its original aspect, depending on your needs a simple way would be to change to UIViewContentModeScaleToFill
if scaling to fill does not produce your intended results, you may want to check out trevor's blog post on uiimage categories here
once the UIImage categories are added you can just perform
[youruiimage resizedImage:CGSizeMake(320, 480) interpolationQuality:kCGInterpolationHigh]
using this you can use either UIViewContentModeScaleToFill or UIViewContentModeScaleAspectFit and it should turn out nicely =)
If you have status bar then don't forget to reduce its size from the height.
And also aspect-fit would keep the image in its correct ratio, then consider filling it.
Aspect-fill would keep the image in correct ration + will try to make full screen, no void spaces, chances are some part of image wont be shown.
Scale to fill will keep the image full screen, ratio doesn't matter there.
I use a VerticalPanel as a container and add to it an Image and a Label widgets. The image widget has been set to use the 100% of the width and 80% of the height of the container. The Label widget has been set to use the 100% of the width and 20% of the height of the container.
Unfortunately, when i load two pictures (of different sizes) in two such containers that have their size fixed (width=120px height=100px - the containers a.k.a VerticalPanel), the images do not appear to have the same size on screen.
Why images appear to have different size when they are displayed on web browser?
Try using setPixelSize() to resize the image as described here: Scaling an Image in GWT
I want to resize an image to a particular width and height without losing its image quality in iphone.
Resize the frame of the image view that contains the image. The image won't change, but it will get smaller. This way you can use the same image for older iPhone screens and Retina Display screens.
If you want to resize the image (so that it takes up less storage space) you'll always lose quality.