简体   繁体   English

UIImageView中的宽高比

[英]Aspect ratio in UIImageView

I got app which can add photo from camera or gallery. 我有可以从相机或画廊添加照片的应用程序。 After adding each photo showes in UIImageView . 添加每张照片后,在UIImageView But they show with bad aspect ratio. 但是它们显示出不良的长宽比。 Photoes are extended on UIImageView's size. 照片将根据UIImageView's大小进行扩展。

How can i show photoes with their real aspect ration? 如何显示照片的真实纵横比?

UPD and what about small pictures? UPD和小图片呢? if user will add really small picture, this picture will resize on all area of UIImageView . 如果用户添加非常小的图片,则此图片将在UIImageView所有区域上调整大小。 How show this pictures in real size? 如何以实际尺寸显示此图片?

Doing myImageView.contentMode = UIViewContentModeScaleAspectFit; 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? 唯一的方法是使用UIGraphicsImageContext ,如此处所述: 使用宽高比调整UIImage的大小?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM