Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aspect ratio in UIImageView

I got app which can add photo from camera or gallery. After adding each photo showes in UIImageView. But they show with bad aspect ratio. Photoes are extended on UIImageView's size.

How can i show photoes with their real aspect ration?

UPD and what about small pictures? if user will add really small picture, this picture will resize on all area of UIImageView. How show this pictures in real size?

like image 592
Eugene Trapeznikov Avatar asked Feb 13 '12 04:02

Eugene Trapeznikov


People also ask

How do I change aspect ratio in UIImage?

To maintain aspect ratio I calculated the width of UIImageView = (320/460)*450 = 313.043 dynamically. And set the contentMode For UIImageView is UIViewContentModeScaleAspectFit.

What is a 2 3 aspect ratio?

2:3 Aspect Ratio. 2:3 is the most popular aspect ratio for printing. Print sizes that are a 2:3 aspect ratio and are popular with poster, canvas, and decal printing are 24 x 36 inches and 40 x 60 inches.

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .


1 Answers

Doing myImageView.contentMode = UIViewContentModeScaleAspectFit; is one option.

But it isn't enough because it changes the aspect ratio of the image, but it doesn't change the source image.

The only way to do that is to use the UIGraphicsImageContext as explained there: Resize UIImage with aspect ratio?

like image 112
Srikar Appalaraju Avatar answered Oct 12 '22 23:10

Srikar Appalaraju